Skip to content

Commit cbe2c09

Browse files
(DOCSP-33844): Fix inaccuracy on tailable cursor doc (#5922) (#5942)
* (DOCSP-33844): Fix inaccuracy on tailable cursor doc * edit * IA template adjustments * add period * avoid 'dead' * reorder * typo * wording * review edits * wording adjustment
1 parent 42fc5b4 commit cbe2c09

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

source/core/tailable-cursors.txt

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@ Tailable Cursors
66

77
.. default-domain:: mongodb
88

9-
By default, MongoDB will automatically close a cursor when the client
10-
has exhausted all results in the cursor. However, for :doc:`capped
11-
collections </core/capped-collections>` you may use a *Tailable
12-
Cursor* that remains open after the client exhausts the results in the
9+
.. facet::
10+
:name: genre
11+
:values: reference
12+
13+
.. contents:: On this page
14+
:local:
15+
:backlinks: none
16+
:depth: 2
17+
:class: singlecol
18+
19+
By default, MongoDB automatically closes a cursor when the client
20+
exhausts all results in the cursor. However, for :ref:`capped
21+
collections <manual-capped-collection>` you can use a :term:`tailable
22+
cursor` that remains open after the client exhausts the results in the
1323
initial cursor. Tailable cursors are conceptually equivalent to the
14-
``tail`` Unix command with the ``-f`` option (i.e. with "follow"
15-
mode). After clients insert new additional documents into a capped
16-
collection, the tailable cursor will continue to retrieve
17-
documents.
24+
``tail`` Unix command with the ``-f`` option ("follow" mode). After
25+
clients insert additional documents into a capped collection, the
26+
tailable cursor continues to retrieve documents.
27+
28+
Use Cases
29+
---------
1830

1931
Use tailable cursors on capped collections that have high write
2032
volumes where indexes aren't practical. For instance,
@@ -23,34 +35,38 @@ tail the primary's :term:`oplog`.
2335

2436
.. note::
2537

26-
If your query is on an indexed field, do not use tailable cursors,
27-
but instead, use a regular cursor. Keep track of the last value of
28-
the indexed field returned by the query. To retrieve the newly
29-
added documents, query the collection again using the last value of
30-
the indexed field in the query criteria, as in the following
31-
example:
38+
If your query is on an indexed field, use a regular cursor instead of
39+
a tailable cursor. Keep track of the last value of the indexed field
40+
returned by the query. To retrieve the newly added documents, query
41+
the collection again using the last value of the indexed field in the
42+
query criteria. For example:
3243

3344
.. code-block:: javascript
3445

3546
db.<collection>.find( { indexedField: { $gt: <lastvalue> } } )
3647

37-
Consider the following behaviors related to tailable cursors:
48+
Get Started
49+
-----------
3850

39-
- Tailable cursors do not use indexes and return documents in
40-
:term:`natural order`.
51+
To create a tailable cursor in :binary:`mongosh`, see
52+
:method:`cursor.tailable()`.
4153

42-
- Because tailable cursors do not use indexes, the initial scan for the
43-
query may be expensive; but, after initially exhausting the cursor,
44-
subsequent retrievals of the newly added documents are inexpensive.
54+
To see tailable cursor methods for your driver, see your :driver:`driver
55+
documentation </>`.
4556

46-
- Tailable cursors may become *dead*, or invalid, if either:
57+
Behavior
58+
--------
4759

48-
- the query returns no match.
60+
Consider the following behaviors related to tailable cursors:
4961

50-
- the cursor returns the document at the "end" of the collection and
51-
then the application deletes that document.
62+
- Tailable cursors do not use indexes. They return documents in
63+
:term:`natural order`.
5264

53-
A *dead* cursor has an ID of ``0``.
65+
- Because tailable cursors do not use indexes, the initial scan for the
66+
query may be expensive. After initially exhausting the cursor,
67+
subsequent retrievals of the newly added documents are inexpensive.
5468

55-
See your :driver:`driver documentation </>` for the
56-
driver-specific method to specify the tailable cursor.
69+
- A tailable cursor can become invalid if the data at its current
70+
position is overwritten by new data. For example, this can happen if
71+
the speed of data insertion is faster than the speed of cursor
72+
iteration.

0 commit comments

Comments
 (0)