【发布时间】:2012-03-11 09:40:07
【问题描述】:
我的集合中有以下代码:
class Author(Agent):
def foo(self):
self.find_another_document_and_update_it(ids)
self.processed = True
self.save()
def find_another_document_and_update_it(self, ids):
for id in ids:
documentA = Authors.objects(id=id)
documentA.update(inc__mentions=1)
在find_another_document_and_update_it() 内部,我查询数据库并检索文档A。然后我在A 中增加一个计数器。然后在foo() 中,在调用find_another_document_and_update_it() 之后,我还保存当前文档,比如说B。问题是虽然我可以看到 A 中的计数器在调用 self.save() 时实际上增加了,但文档 A 被重置为其旧值。我猜这个问题与并发问题以及 MongoDB 如何处理它有关。感谢您的帮助。
【问题讨论】:
标签: mongodb mongoengine