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?
views:
35answers:
1
+1
A:
Actually, you can update multiple docs with the multi option:
collection.update(spec, doc, multi=True)
This updates all matches.
kristina
2010-06-29 23:48:23
Sorry, could you be more specific? Say that I pull 10 objects from the database, each with a unique `_id`, and I change one field in each. How do I then put those changes in the database? Bonus points for both simplicity and query efficiency.
Trevor Burnham
2010-06-30 01:16:45
Are each of the changes different? If so, you'll have to do separate updates. You can't batch them, but I doubt that being unable to send them together is a bottleneck.
kristina
2010-06-30 22:26:18
Ah, I see. Thanks.
Trevor Burnham
2010-07-01 16:20:22