开发者

Multiple simultaneous updates with MongoDB/PyMongo?

开发者 https://www.devze.com 2023-01-05 08:16 出处:网络
Accord开发者_开发问答ing 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

Accord开发者_开发问答ing 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

0

精彩评论

暂无评论...
验证码 换一张
取 消