When working with transactions, how do I achieve lock the reads as well?
I am working with a method that replaces the document (using UpdateOneAndAsync does not work in this case), so I need to use transactions to achieve atomicity and not allow multiple writes. This works fine, but I notice that the reads are not locked, meaning that I am able to read the document that I have lock-in another transaction, is there a way to lock the read as well?
When working with transactions, how do I achieve lock the reads as well?
In short, I don’t think you can. Transactions mainly concerns document writes and not presenting a state of the database that is not consistent, not really about preventing reads. Preventing readers would likely have a negative effect on your database’s parallelism and performance.
However, do you mind elaborating more if you have a specific use case in mind that requires you to prevent reads? Some example scenarios would be helpful to illustrate the point.
Hey @kevinadi , I’m looking for the same kind of read locks, my use case is that of creating a history/audit log, which has to be in the order of updates to the same document.