-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcursor.addOption.txt
109 lines (82 loc) · 3.23 KB
/
cursor.addOption.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
==================
cursor.addOption()
==================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: cursor.addOption(flag)
.. include:: /includes/fact-mongosh-shell-method.rst
.. note:: Deprecated since v3.2
Starting in v3.2, the ``cursor.addOption()`` operator is
deprecated in :binary:`~bin.mongo`. Use available :ref:`cursor
methods <doc-cursor-methods>` instead.
Used to change query behavior by setting the flags listed below.
The ``cursor.addOption()`` method has the following parameter:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Parameter
- Type
- Description
* - ``flag``
- flag
- For :binary:`~bin.mongosh`, you can use the cursor flags
listed below. For the driver-specific list, see your
:driver:`driver documentation </>`.
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-limited-free-and-m10.rst
.. include:: /includes/fact-environments-onprem-only.rst
.. _cursor-flags:
Flags
-----
:binary:`~bin.mongosh` provides several additional cursor flags to
modify the behavior of the cursor.
.. list-table::
:header-rows: 1
:widths: 30 70
* - Flag
- Description
* - .. data:: DBQuery.Option.tailable
- Sets the cursor not to close once the last data is
received, allowing the query to continue returning data added
after the initial results were exhausted.
* - .. data:: DBQuery.Option.slaveOk
- Allows querying of a replica secondary.
* - .. data:: DBQuery.Option.noTimeout
- Prevents the server from timing out idle cursors.
* - .. data:: DBQuery.Option.awaitData
- For use with :data:`DBQuery.Option.tailable`.
Sets the cursor to block the query thread when no data is
available and await data for a set time instead of immediately
returning no data. The cursor returns no data only if the
timeout expires.
* - .. data:: DBQuery.Option.exhaust
- Sets the cursor to return all data returned by the
query at once rather than splitting the results into batches.
* - .. data:: DBQuery.Option.partial
- Sets the cursor to return partial data from a query against a
sharded cluster in which some shards do not respond rather than
throwing an error.
Example
-------
The following example adds the ``DBQuery.Option.tailable`` flag and the
``DBQuery.Option.awaitData`` flag to ensure that the query returns a
:ref:`tailable cursor <tailable-cursors-landing-page>`. The sequence
creates a cursor. After returning the full result set, it waits for the
default interval of 1000 milliseconds so that it can capture
and return additional data added during the query:
.. code-block:: javascript
var t = db.myCappedCollection;
var cursor = t.find().addOption(DBQuery.Option.tailable).
addOption(DBQuery.Option.awaitData)
.. warning::
Adding incorrect wire protocol flags can cause problems and/or
extra server load.