我在集合中有以下代码:
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 如何处理它有关。我感谢您的帮助。