0
我有一個集合在下面的代碼:更新文件 - mongoengine
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如何處理它。我感謝您的幫助。