Let's suppose I am running the following command on multiple concurrent threads:
db.tasks.findAndModify({
query: { status : "TODO" },
update: { $set: { status : "DONE" } },
new: true
})
From this command it's obvious that each document should be updated exactly once, since after the update the query no longer matches the state of the document. This implies that each running thread will get a different task
on each execution.
Is this something that Mongo guarantees without the need for extra transactions? I've read similar questions about concurrency and document-level locking but none of them seems to be matching my case where the update operation modifies fields referenced on the query.
I am using Mongo 4.0 with WiredTiger storage engine if that's relevant.