2

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?

zhaochy
  • 734
  • 7
  • 12

1 Answers1

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:

  1. A finds the document
  2. B wants to find the document but it's prevented
  3. A updates the document
  4. B finds the document
  5. B updates the document
  6. document value is B

With findAnyModify:

  1. A finds the document
  2. B finds the document
  3. B updates the document
  4. A updates the document
  5. document value is A

Further reading: What's the difference between findAndModify and update in MongoDB?

Community
  • 1
  • 1
Alon
  • 10,381
  • 23
  • 88
  • 152