Skip to content

Commit 10fa2c3

Browse files
author
Chris Cho
authored
DOCSP-10199: cursor feedback fixes (#94)
* DOCSP-10199: cursor feedback fixes
1 parent fb12d9a commit 10fa2c3

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

source/code-snippets/crud/cursor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async function streamAPI(collection) {
5353
async function eventAPI(collection) {
5454
// start event cursor example
5555
const cursor = collection.find({});
56+
// the "data" event is fired once per document
5657
cursor.on("data", data => console.log(data));
5758
// end event cursor example
5859
}

source/fundamentals/crud.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ set for viewing.
9090
:end-before: end aggregate crud example
9191
:dedent: 4
9292

93+
.. _watch-subscribe:
94+
9395
Watch / Subscribe
9496
~~~~~~~~~~~~~~~~~
9597

source/fundamentals/crud/read-operations/cursor.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ The following functions directly return cursors:
2424

2525
- ``Db.listCollections()``
2626

27-
Other methods, like :doc:`Collection.findOne()
28-
</usage-examples/findOne>` and ``Collection.watch()``,
29-
use cursors to return results but do not directly expose those
30-
cursors to the method caller.
27+
Other methods such as :doc:`Collection.findOne() </usage-examples/findOne>`
28+
and :doc:`Collection.watch() </fundamentals/crud#watch-subscribe>` use
29+
cursors internally, and return the results of the operations instead of
30+
a cursor.
3131

3232
Cursor Paradigms
3333
----------------
@@ -52,6 +52,12 @@ pulling all matching documents into a collection in process memory.
5252
undefined behaviour. Always wait for the previous
5353
asynchronous operation to complete before running another.
5454

55+
.. note::
56+
57+
When you reach the last result through iteration or through an at-once
58+
fetch, the cursor is exhausted which means it ceases to respond to methods
59+
that access the results.
60+
5561
For Each Functional Iteration
5662
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5763

@@ -95,8 +101,9 @@ method to retrieve the subsequent element of the cursor:
95101
Stream API
96102
~~~~~~~~~~
97103

98-
All cursors are Node Readable Streams operating in Object Mode. Cursors
99-
will work with most Node stream APIs:
104+
All cursors are Node Readable Streams that operate in **Object Mode** which
105+
passes JavaScript objects rather than Buffers or Strings through the
106+
pipeline. Cursors work with most Node stream APIs:
100107

101108
.. literalinclude:: /code-snippets/crud/cursor.js
102109
:language: javascript
@@ -131,6 +138,7 @@ exceeding memory constraints.
131138
:end-before: end fetchAll cursor example
132139
:dedent: 4
133140

141+
134142
Cursor Utility Methods
135143
----------------------
136144

0 commit comments

Comments
 (0)