Lock the document field (not the entire document)
Hi
according to this reference: https://www.mongodb.com/blog/post/how-to-select--for-update-inside-mongodb-transactions
When I lock a document with a field with a new ObjectID, the whole document is locked!
Idea :
Operations:
i have three fields : A , B , C
I locked field A
with new ObjectID in transaction T1
.
i locked field B
with new ObjectID in transaction T2
.
Behaviors (high performance) :
- In transaction T2
: if field A
is updated, writeConflict
error occurs.
- In transaction T1
: if field B
is updated, writeConflict
error occurs.
- Outside of transactions: If field A
is updated, it waits for T1
.
- Outside of transactions: If field B
is updated, it waits for T2
.
- T1 and T2 transaction can be commit at same time. (high performance)
https://www.mongodb.com/community/forums/t/lock-on-sub-document-in-mongo/140245
![](https://secure.gravatar.com/avatar/cce61130da60abe62d60f5a8f685c07c?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)