Skip to content

WRITING-1480: Fix build warning regarding missing cursor documentation #2530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/redirects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,20 @@ code: 303
outputs:
- 'before-v3.0'
---
from: '/reference/method/cursor.noCursorTimeout'
to: '/reference/method'
type: 'redirect'
code: 303
outputs:
- 'before-v3.0'
---
from: '/reference/method/cursor.close'
to: '/reference/method'
type: 'redirect'
code: 303
outputs:
- 'before-v3.0'
---
from : '/reference/command/geoWalk'
to: '/reference/command/nav-geospatial/'
type: 'redirect'
Expand Down
17 changes: 8 additions & 9 deletions source/core/cursors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,19 @@ Closure of Inactive Cursors
~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default, the server will automatically close the cursor after 10
minutes of inactivity or if client has exhausted the cursor. To
override this behavior, you can specify the ``noTimeout`` flag in your
query using :method:`cursor.addOption()`; however, you should either
close the cursor manually or exhaust the cursor. In the
:program:`mongo` shell, you can set the ``noTimeout`` flag:
minutes of inactivity, or if client has exhausted the cursor. To
override this behavior in the :program:`mongo` shell, you can use
the :method:`cursor.noCursorTimeout()` method:

.. code-block:: javascript

var myCursor = db.inventory.find().addOption(DBQuery.Option.noTimeout);
var myCursor = db.inventory.find().noCursorTimeout();

After setting the ``noCursorTimeout`` option, you must either close the cursor
manually with :method:`cursor.close()` or by exhausting the cursor's results.

See your :doc:`driver </applications/drivers>` documentation for
information on setting the ``noTimeout`` flag. For the :program:`mongo`
shell, see :method:`cursor.addOption()` for a complete list of
available cursor flags.
information on setting the ``noCursorTimeout`` option.

.. _cursor-isolation:

Expand Down
8 changes: 8 additions & 0 deletions source/includes/ref-toc-method-cursor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: ":method:`cursor.batchSize()`"
file: /reference/method/cursor.batchSize
description: "Controls the number of documents MongoDB will return to the client in a single network message."
---
name: ":method:`cursor.close()`"
file: /reference/method/cursor.close
description: "Close a cursor and free associated server resources."
---
name: ":method:`cursor.comment()`"
file: /reference/method/cursor.comment
description: "Attaches a comment to the query to allow for traceability in the logs and the system.profile collection."
Expand Down Expand Up @@ -58,6 +62,10 @@ name: ":method:`cursor.next()`"
file: /reference/method/cursor.next
description: "Returns the next document in a cursor."
---
name: ":method:`cursor.noCursorTimeout()`"
file: /reference/method/cursor.noCursorTimeout
description: "Instructs the server to avoid closing a cursor automatically after a period of inactivity."
---
name: ":method:`cursor.objsLeftInBatch()`"
file: /reference/method/cursor.objsLeftInBatch
description: "Returns the number of documents left in the current cursor batch."
Expand Down
23 changes: 23 additions & 0 deletions source/reference/method/cursor.close.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
==============
cursor.close()
==============

.. default-domain:: mongodb

Definition
----------

.. method:: cursor.close()

Instructs the server to close a :ref:`cursor <read-operations-cursors>`
and free associated server resources. The server will automatically close
cursors that have no remaining results, as well as cursors that have been
idle for a period of time and lack the :method:`cursor.noCursorTimeout()`
option.

The :method:`~cursor.close()` method has the following
prototype form:

.. code-block:: javascript

db.collection.find(<query>).close()
20 changes: 20 additions & 0 deletions source/reference/method/cursor.noCursorTimeout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
========================
cursor.noCursorTimeout()
========================

.. default-domain:: mongodb

Definition
----------

.. method:: cursor.noCursorTimeout()

Instructs the server to avoid closing a cursor automatically after a period
of inactivity.

The :method:`~cursor.noCursorTimeout()` method has the following
prototype form:

.. code-block:: javascript

db.collection.find(<query>).noCursorTimeout()
19 changes: 11 additions & 8 deletions source/reference/method/db.collection.find.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,17 @@ array:
Iterate the Returned Cursor
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The :method:`~db.collection.find()` method returns a :term:`cursor` to
the results. In the :program:`mongo` shell, if the returned cursor is
not assigned to a variable using the ``var`` keyword, the cursor is
automatically iterated up to 20 times to access up to the first 20
documents that match the query. You can use the
``DBQuery.shellBatchSize`` to change the number of iterations. See
:ref:`cursor-flags` and :ref:`cursor-behaviors`. To iterate manually,
assign the returned cursor to a variable using the ``var`` keyword.
The :method:`~db.collection.find()` method returns a
:ref:`cursor <read-operations-cursors>` to the results.

In the :program:`mongo` shell, if the returned cursor is not assigned to a
variable using the ``var`` keyword, the cursor is automatically iterated to
access up to the first 20 documents that match the query. You can set the
``DBQuery.shellBatchSize`` variable to change the number of automatically
iterated documents.

To manually iterate over the results, assign the returned cursor to a variable
with the ``var`` keyword, as shown in the following sections.

With Variable Name
``````````````````
Expand Down
4 changes: 2 additions & 2 deletions source/tutorial/getting-started-with-the-mongo-shell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ From the :program:`mongo` shell, you can use the :doc:`shell methods
times.

You can set the ``DBQuery.shellBatchSize`` attribute to change the
number of iteration from the default value ``20``, as in the
number of documents from the default value of ``20``, as in the
following example which sets it to ``10``:

.. code-block:: javascript
Expand Down Expand Up @@ -290,4 +290,4 @@ Exit the Shell

To exit the shell, type ``quit()`` or use the ``<Ctrl-c>`` shortcut.

.. seealso:: :gettingstarted:`Getting Started Guide </shell>`
.. seealso:: :gettingstarted:`Getting Started Guide </shell>`