@@ -51,7 +51,7 @@ pulling all matching documents into a collection in process memory.
5151.. warning::
5252
5353 Do not combine different cursor paradigms on a single cursor.
54- Operations such as ``hasNext()``, ``forEach()``, and ``toArray()``
54+ Operations such as ``hasNext()`` and ``toArray()``
5555 each predictably modify the original cursor. If you mix these calls
5656 on a single cursor, you may receive unexpected results.
5757
@@ -68,44 +68,14 @@ pulling all matching documents into a collection in process memory.
6868 fetch, the cursor is exhausted which means it ceases to respond to methods
6969 that access the results.
7070
71- .. _node-fundamentals-cursor-foreach:
72-
73- For Each Functional Iteration
74- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75-
76- You can pass a function to the `forEach() <{+api+}/classes/FindCursor.html#forEach>`__ method of any cursor to iterate through
77- results in a functional style:
78-
79- .. literalinclude:: /code-snippets/crud/cursor.js
80- :language: javascript
81- :start-after: start foreach cursor example
82- :end-before: end foreach cursor example
83-
84- .. _node-fundamentals-cursor-array:
85-
86- Return an Array of All Documents
87- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88-
89- For use cases that require all documents matched by a query to be held
90- in memory at the same time, use `toArray() <{+api+}/classes/FindCursor.html#toArray>`__.
91- Note that large numbers of matched documents can cause performance issues
92- or failures if the operation exceeds memory constraints. Consider using
93- `forEach() <{+api+}/classes/FindCursor.html#forEach>`__ to iterate
94- through results unless you want to return all documents at once.
95-
96- .. literalinclude:: /code-snippets/crud/cursor.js
97- :language: javascript
98- :start-after: start fetchAll cursor example
99- :end-before: end fetchAll cursor example
100-
10171.. _node-fundamentals-async-iteration:
10272
10373Asynchronous Iteration
10474~~~~~~~~~~~~~~~~~~~~~~
10575
10676Cursors implement the :mdn:`AsyncIterator
10777<Web/JavaScript/Reference/Statements/for-await...of>` interface, which
108- allows you to use cursors in ``for`` ...``await `` loops:
78+ allows you to use cursors in ``for await ...of `` loops:
10979
11080.. literalinclude:: /code-snippets/crud/cursor.js
11181 :language: javascript
@@ -125,6 +95,23 @@ method to retrieve the subsequent element of the cursor:
12595 :start-after: start manual cursor example
12696 :end-before: end manual cursor example
12797
98+ .. _node-fundamentals-cursor-array:
99+
100+ Return an Array of All Documents
101+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102+
103+ For use cases that require all documents matched by a query to be held
104+ in memory at the same time, use the `toArray() <{+api+}/classes/FindCursor.html#toArray>`__
105+ method. Note that large numbers of matched documents can cause performance issues
106+ or failures if the operation exceeds memory constraints. Consider using
107+ the ``for await...of`` syntax to iterate
108+ through results rather than returning all documents at once.
109+
110+ .. literalinclude:: /code-snippets/crud/cursor.js
111+ :language: javascript
112+ :start-after: start fetchAll cursor example
113+ :end-before: end fetchAll cursor example
114+
128115Stream API
129116~~~~~~~~~~
130117
0 commit comments