Hello community,
I’m building a demo app that involves some dummy wallet transactions. In this app, I want to properly handle race conditions, ensuring that no wallet balance ever drops below zero (or a set minimum balance). To achieve this, I’m using the $inc operator within transactions.
My question is: if a wallet document is locked by a findOneAndUpdate operation inside a transaction (because its balance is being updated), will another findOneAndUpdate be blocked from even finding the document until the first transaction completes? And if so, does the find query need to reflect the most up-to-date state of the document once the lock is released? Or will it be able to find the document immediately but have to wait for the lock before applying the update?