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
$incoperator within transactions.
You don’t need a transaction for this. A single update is 100% atomic and transactional - there is no extra benefit to wrapping it in a transaction.
You also don’t need findOneAndUpdate when you just need to update - you only need it if you have to get back the updated document.
But separately from your example which doesn’t need transactions, if a running transaction has updated a document, this document is still available in the current snapshot to be found by other read operations, since it has not yet been committed.
Asya