I have a list of dictionary like
{'data': '[{"url":"https://example1.com/photos-reviews/","score":0.671},{"url":"https://example1.com/concerts-events/concert-organ-performances/2018-2019/","score":0.662},{"url":"https://www.example2.org/support-volunteer/orchestra-league/","score":0.645}]', 'type': 'invalid'}
The field url is unique and based on the field type (invalid or valid - Here invalid), the field hum_proc in the mongodb which is by default null will be changed to invalid or valid respectively.
I did this by
@sources_api.route('pending_val', methods=["GET", "POST"])
def pending_val():
if request.method=='POST':
data_rec = request.get_json()
if 'type' in data_rec:
data_list= json.loads(data_rec["data"])
for val in data_list:
MlData.objects(url=val["url"]).update_one(set__hum_proc=data_rec["type"])
I am iterating and updating each item. Is it possible to update this in a single step more efficiently using aggregation pipeline or so