我想要使用mongo的 findAndmodify, 去查询并修改一条数据,比如:
查询前的条件是
{usage: false}
查询并修改后
{usage:true}
按正常的逻辑,查询了一次就不会被其他查询到。但是当并发量很大的时候,有没有可能两个查询并修改都修改了同一条数据。
我想要使用mongo的 findAndmodify, 去查询并修改一条数据,比如:
查询前的条件是
{usage: false}
查询并修改后
{usage:true}
按正常的逻辑,查询了一次就不会被其他查询到。但是当并发量很大的时候,有没有可能两个查询并修改都修改了同一条数据。
mongodb 的文档里写了.
When modifying a single document, both
findAndModify
and theupdate()
") 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.