Answers for "how to bulk update in mongodb using python"

0

how to bulk update in mongodb using python

import pymongo
conn = pymongo.MongoClient('myserver', 8839)
db = conn['mydbname']
coll = db.myCollection
bulkop = coll.initialize_ordered_bulk_op()
retval = bulkop.find({'field1':1}).upsert().update({'$push':{'vals':1}})
retval = bulkop.find({'field1':1}).upsert().update({'$push':{'vals':2}})
retval = bulkop.find({'field1':1}).upsert().update({'$push':{'vals':3}})
retval = bulkop.execute()
Posted by: Guest on December-18-2020

Code answers related to "how to bulk update in mongodb using python"

Python Answers by Framework

Browse Popular Code Answers by Language