Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Database
Created by Guest
Created on Mar 21, 2023

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
  • Attach files