How atomic are mongoengine's operations

…衆ロ難τιáo~ 提交于 2019-12-12 19:11:20

问题


I'm trying to transition between object's state like so:

User.objects(id=user_id, state=STATE_WAITING).update_one(set__state=STATE_FINISHED)

The question is, can there be a situation where two processes will make the same operation asynchronously and succeed?

If so, can this operation be atomic, so the next process that will try to update the user (at the same time asynchronously), will fail because it's status will be already "finished"?


回答1:


When writing on a single document, the operation is atomic.

In MongoDB, a write operation is atomic on the level of a single document, even if the operation modifies multiple embedded documents within a single document.

When writing on multiple documents that is not atomic.

Further, a multi document transaction can be simulated using a two phase commit, details here.



来源:https://stackoverflow.com/questions/40398631/how-atomic-are-mongoengines-operations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!