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