How does MongoDB cursor behave when the collection is being changed?

672 Views Asked by At

Suppose I'm using the cursor to iterate a subset of the documents, ordered by some field let's say.

What happens if while iterating, a new document is being inserted or a current one is being deleted?

Would that affect the cursor or does it MongoDB make some sort of snapshot of the data?

1

There are 1 best solutions below

0
D. SM On BEST ANSWER

When you are in a transaction with read concern snapshot, you are reading from a consistent snapshot of the data.

Otherwise you could be experiencing various phenomena described here.