The $isolated
and findAndModify
in mongodb both prevent other processes change the document. I am confused about the different of this two method, what is the difference between them?
Asked
Active
Viewed 294 times
2

zhaochy
- 734
- 7
- 12
1 Answers
1
findAndModify
does not prevent other processes change the document.
Let's say that processes A and B both try to update a document at the same time.
With $isolated
:
- A finds the document
- B wants to find the document but it's prevented
- A updates the document
- B finds the document
- B updates the document
- document value is B
With findAnyModify
:
- A finds the document
- B finds the document
- B updates the document
- A updates the document
- document value is A
Further reading: What's the difference between findAndModify and update in MongoDB?