mongo的findModify是原子性的吗?

我想要使用mongo的 findAndmodify, 去查询并修改一条数据,比如:

查询前的条件是
{usage: false}
查询并修改后
{usage:true}

按正常的逻辑,查询了一次就不会被其他查询到。但是当并发量很大的时候,有没有可能两个查询并修改都修改了同一条数据。

阅读 3.7k
1 个回答

mongodb 的文档里写了.

When modifying a single document, both findAndModify and the update()") method atomically update the document. See Atomicity and Transactions for more details about interactions and order of operations of these methods.

Atomicity

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.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进