I am trying to update mongodb collection from Python using condition on _id
Like if I found match of _id in python dataframe I need to update corresponding document in colllection Below script is working, but it takes time for exeution if there are too many document is there any efficient way to handle this. Please advice
for document in db.AMTicketData.find():
for index, row in AMTicketData1.iterrows():
if(row['_id']==a['_id']):
db.AMTicketData.update_one({'_id': row['_id']},{'$set': {'Application_Name': row['Application_Name']}}, upsert=True)
break
I have used below bulk operation codes, was able to update collection in bulk
bulk = db.AMTicketData.initialize_unordered_bulk_op()
for index, row in AMTicketData1.iterrows():
bulk.find({'_id':row['_id']}).update_one({'$set':{'Application_Name':row['Application_Name']}})
bulk.execute()