【发布时间】:2015-09-05 17:28:15
【问题描述】:
我想批量更新 mongoengine 文档实例中的更改,但据我了解,model.objects.update(...) 在所有符合条件的文档中进行相同的更新。
例子:
entities = Foo.objects
result = entities.update(
set__foo='new bar',
upsert=True,
full_result=True)
这会将所有foo 等于bar 的文档的属性foo 设置为new bar。我想对每个文档进行不同的更改。
这可能吗?像这样的:
entities = Foo.objects
... # make changes to each entity in entities
entities = Foo.objects.update(entities)
# these entities were bulk updated in mongodb.
【问题讨论】:
标签: python pymongo mongoengine