Skip to content

Commit 3e25fc4

Browse files
committed
DOCS-690 snapshot query page
1 parent b7398eb commit 3e25fc4

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

source/faq/developers.txt

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -466,41 +466,36 @@ driver <>`.
466466

467467
db.getCollection("_foo").find()
468468

469-
.. _faq-developers-snapshot-queries:
469+
.. _faq-developers-isolate-cursors:
470470

471-
How do I perform a snapshot query in MongoDB?
472-
---------------------------------------------
471+
How do I isolate cursors from intervening write operations?
472+
-----------------------------------------------------------
473473

474-
MongoDB does not support full point-in-time snapshot where the cursor
475-
returned from a query points to the records at the time of the
476-
query execution, regardless of additional write operations that may
477-
have occurred during the lifetime of the cursor. However, MongoDB does
478-
provides a :method:`snapshot() <cursor.snapshot()>` method to prevent
479-
the case where a cursor could return a document more than once because
480-
an intervening write operation results in a move of the document due to
481-
the growth in document size.
474+
During the lifetime of the cursor, an intervening write operation can
475+
result in a move of the document due to the growth in document size.
476+
This may cause the cursor to return the document more than once. To
477+
prevent this from happening, you can use the :method:`snapshot()
478+
<cursor.snapshot()>` method.
482479

483-
When applied to the cursor returned from :method:`find()`,
484-
:method:`snapshot() <cursor.snapshot()>` assures that the cursor
485-
returns a document no more than once.
480+
The :method:`snapshot() <cursor.snapshot()>` method traverses the index
481+
on the ``_id`` field. As such, :method:`snapshot() <cursor.snapshot()>`
482+
**cannot** be used with :method:`sort() <cursor.sort()>` or
483+
:method:`hint() <cursor.hint()>`.
486484

487-
.. note::
485+
The :method:`snapshot() <cursor.snapshot()>` does not guarantee
486+
isolation from insertion or deletions.
487+
488+
.. warning::
489+
490+
You can only use :method:`snapshot() <cursor.snapshot()>` with
491+
**unsharded** collections.
492+
493+
Alternatively, if there are field or fields that are never modified,
494+
you can use a *unique* index on this field or these fields to achieve
495+
the same effect as the :method:`snapshot() <cursor.snapshot()>`. Query
496+
with :method:`hint() <cursor.hint()>` to explicitly force the use of
497+
that index.
488498

489-
- Even with :method:`snapshot() <cursor.snapshot()>`, objects
490-
inserted or deleted during the lifetime of the cursor may or may
491-
not be returned.
492-
493-
- The :method:`snapshot() <cursor.snapshot()>` method traverses the
494-
index on the ``_id``. As such, :method:`snapshot()
495-
<cursor.snapshot()>` **cannot** be used with :method:`sort()
496-
<cursor.sort()>` or :method:`hint() <cursor.hint()>`. No other
497-
index can be used for the query.
498-
499-
- Alternatively, instead of :method:`snapshot()
500-
<cursor.snapshot()>`, you can use a *unique* index on field(s)
501-
that will not be modified and use :method:`hint() <cursor.hint()>`
502-
to explicitly force that index during the query in order to
503-
achieve the same :method:`snapshot() <cursor.snapshot()>` mode.
504-
Additionally, to use a non-unique index on field(s) that will not
505-
be modified, you can create a unique index by including the
506-
``_id`` field to the index fields.
499+
If you want to use a non-unique index on field(s) that will not be
500+
modified, you can create a unique index by including the ``_id`` field
501+
to the index fields.

source/reference/method/cursor.snapshot.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,28 @@ cursor.snapshot()
66

77
.. method:: cursor.snapshot()
88

9-
Append the :method:`cursor.snapshot()` method to a cursor to toggle the
10-
"snapshot" mode. This ensures that the query will not miss any
11-
documents and return no duplicates, even if other operations modify
12-
objects while the query runs.
9+
Append the :method:`cursor.snapshot()` method to a cursor to toggle
10+
the "snapshot" mode. This ensures that the query will not return a
11+
document multiple times, even if intervening write operations result
12+
in a move of the document due to the growth in document size.
1313

14-
.. note::
14+
.. warning::
1515

16-
You must apply :method:`cursor.snapshot()` to the cursor before
17-
retrieving any documents from the database.
16+
- You must apply :method:`cursor.snapshot()` to the cursor before
17+
retrieving any documents from the database.
1818

19+
- You can only use :method:`snapshot() <cursor.snapshot()>` with
20+
**unsharded** collections.
21+
22+
The :method:`snapshot() <cursor.snapshot()>` does not guarantee
23+
isolation from insertion or deletions.
24+
25+
The :method:`cursor.snapshot()` traverses the index on the ``_id``
26+
field. As such, :method:`snapshot() <cursor.snapshot()>` **cannot**
27+
be used with :method:`sort() <cursor.sort()>` or :method:`hint()
28+
<cursor.hint()>`.
29+
30+
31+
1932
Queries with results of less than 1 megabyte are effectively
2033
implicitly snapshotted.

0 commit comments

Comments
 (0)