It's not possible to lock a mongodb document. What if I need to?

前端 未结 12 1724
死守一世寂寞
死守一世寂寞 2020-12-24 11:34

I know that I can\'t lock a single mongodb document, in fact there is no way to lock a collection either.

However, I\'ve got this scenario, where I think I need some

12条回答
  •  忘掉有多难
    2020-12-24 12:19

    Stumbled into this question while working on mongodb upgrades. Unlike at the time this question was asked, now mongodb supports document level locking out of the box.

    From: http://docs.mongodb.org/manual/faq/concurrency/

    "How granular are locks in MongoDB?

    Changed in version 3.0.

    Beginning with version 3.0, MongoDB ships with the WiredTiger storage engine, which uses optimistic concurrency control for most read and write operations. WiredTiger uses only intent locks at the global, database and collection levels. When the storage engine detects conflicts between two operations, one will incur a write conflict causing MongoDB to transparently retry that operation."

提交回复
热议问题