How To SELECT ... FOR UPDATE inside MongoDB Transactions
The text discusses how to ensure that documents read within a transaction in MongoDB are not modified by another operation before the commit. It explains how concurrency works in MongoDB, both inside and outside of transactions, focusing on locking mechanisms and write conflicts. To prevent other operations from modifying documents being read within a transaction, it suggests emulating a "write lock" by updating a document with an exclusive attribute, such as ObjectId. This method ensures that the document is locked until the transaction is committed or aborted. The text also emphasizes that MongoDB's flexible schema often eliminates the need for transactions altogether and should be used judiciously.
Company
MongoDB
Date published
Oct. 15, 2019
Author(s)
Renato Riccio
Word count
1302
Hacker News points
None found.
Language
English