According to the PyMongo docs, update()
can only update a single document at a time. Let's say I have 100 documents I want to update simultaneously. That's a lot of overhead. Is there a way to update multiple documents with a single MongoDB query through PyMongo?
Actually, you can update multiple docs with the multi option:
collection.update(spec, doc, multi=True)
This updates all matches.
you can update multiple documents with different _id at a time by using bulk write feature available in mongodb 2.6 try this http://api.mongodb.org/python/current/examples/bulk.html
in precise you can use Ordered Bulk Write Operations which updates a bulk of records which are with different criteria.
view this for more details Best way to read and update mongodb documents using pymongo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With