翻译或纠错本页面
- Reference >
- Operators >
- Query Modifiers >
- $snapshot
$snapshot¶
- $snapshot¶
注解
- Deprecated in the mongo Shell since v3.2
- Starting in v3.2, the $snapshot operator is deprecated in the mongo shell. In the mongo shell, use cursor.snapshot() instead.
The $snapshot operator 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 mongo shell provides the cursor.snapshot() method:
db.collection.find().snapshot()
You can also specify the option in either of the following forms:
db.collection.find()._addSpecial( "$snapshot", true ) db.collection.find( { $query: {}, $snapshot: true } )
The $snapshot operator traverses the index on the _id field [1].
警告
- You cannot use $snapshot with sharded collections.
- Do not use $snapshot with $hint or $orderby (or the corresponding cursor.hint() and cursor.sort() methods.)
[1] You can achieve the $snapshot isolation behavior using any unique index on invariable fields.