I have an application that tries to update the same row in a collection in 2 separate threads at the same time. Each thread has its own connection the MongoDB server and has started a transaction.
Thread 1 has altered the row and the 2nd thread tries to update the same row when MongoDB returns the write conflict error. The 2nd thread waits 5 millisecs and then tries to update the row again, when MongoDB returns transaction aborted.
Each thread is updating and inserting into multiple documents in the transaction.
This a major issue for us, is this a bug?
I changed the app to work as separate processes instead of multiple threads and I still get the same issue.
I understand your logic for explaining a write conflict, however in a multi-user transaction based environment that should not happen, thread B after updating the row should have it locked and blocking thread A until thread B commits/rollback or thread A gets a transaction timeout.
If MongoDB is not working as above then it cannot be used in a multi-user environment that requires updates in a transaction to block other users.
My understanding is that if you update a row in MongoDB it locks it.