- Reference >
- Operators >
- Query Modifiers >
- $snapshot
$snapshot¶
-
$snapshot¶ The
$snapshotoperator prevents the cursor from returning a document more than once because an intervening write operation results in a move of the document.Even in snapshot mode, objects inserted or deleted during the lifetime of the cursor may or may not be returned.
The
mongoshell provides thecursor.snapshot()method:You can also specify the option in either of the following forms:
The
$snapshotoperator traverses the index on the_idfield [1].Warning
- You cannot use
$snapshotwith sharded collections. - Do not use
$snapshotwith$hintor$orderby(or the correspondingcursor.hint()andcursor.sort()methods.)
[1] You can achieve the $snapshotisolation behavior using any unique index on invariable fields.- You cannot use