Skip to content

Commit e77ec8d

Browse files
committed
DOCS-675 incorporated Scotts feedback
1 parent 35c1f8b commit e77ec8d

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

source/core/read-operations.txt

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -741,31 +741,36 @@ information on cursor methods.
741741
Iterator Index
742742
~~~~~~~~~~~~~~
743743

744-
Additionally, with some of the :doc:`drivers </applications/drivers>`,
745-
you can iterate with an index (i.e. ``cursor[index]``) and return the
746-
document at the index position, as in the following example:
744+
In the :program:`mongo` shell, you can use the ``toArray()`` method to
745+
iterate the cursor and return the documents in an array, as in the
746+
following:
747747

748748
.. code-block:: javascript
749749

750750
var myCursor = db.inventory.find( { type: 'food' } );
751+
var documentArray = myCursor.toArray();
752+
var myDocument = documentArray[3];
751753

752-
myDoc = myCursor[3];
754+
The ``toArray()`` method loads into RAM all documents returned by the
755+
cursor; the ``toArray()`` method exhausts the cursor.
753756

754-
Accessing the document with an index iterates the cursor and loads into
755-
RAM the documents up to the index and should not be used for queries
756-
which may return very large number of data that may exceed memory.
757+
Additionally, some :doc:`drivers </applications/drivers>` provide
758+
access to the documents by using an index on the cursor (i.e.
759+
``cursor[index]``). This is a shortcut for first calling the
760+
``toArray()`` method and then using an index on the resulting array.
757761

758-
In the :program:`mongo` shell, you can use the ``toArray()`` method to
759-
iterate the cursor and return the documents in an array, as in the
760-
following:
762+
Consider the following example:
761763

762764
.. code-block:: javascript
763765

764766
var myCursor = db.inventory.find( { type: 'food' } );
765-
var documentArray = myCursor.toArray();
767+
var myDocument = myCursor[3];
766768

767-
The ``toArray()`` method loads into RAM all documents returned by the
768-
cursor.
769+
The ``myCursor[3]`` is equivalent to the following example:
770+
771+
.. code-block:: javascript
772+
773+
myCursor.toArray() [3];
769774

770775
.. TODO link to toArray() method once the page has been added
771776

@@ -777,31 +782,29 @@ Consider the following behaviors related to cursors:
777782
- By default, the server will automatically close the cursor after 10
778783
minutes of inactivity or if the cursor has been exhausted. To
779784
override this behavior, you can specify the "noTimeout" :wiki:`wire
780-
protocol option <Mongo Wire Protocol>` in your query; however, you
785+
protocol flag <Mongo Wire Protocol>` in your query; however, you
781786
should either close the cursor manually or exhaust the cursor. In the
782-
:program:`mongo` shell, you can set the "noTimeout" option. See your
787+
:program:`mongo` shell, you can set the "noTimeout" flag. See your
783788
:doc:`driver </applications/drivers>` documentation for information
784789
on setting the "noTimeout" option.
785790

786-
- Write operations may interleave during latent access to the cursor.
787-
This may cause a document to be returned multiple times. To handle
788-
this situation, see the information on :wiki:`snapshot mode <How to do
789-
Snapshotted Queries in the Mongo Database>`.
790-
791-
.. TODO link instead to faq snapshot when that becomes available.
791+
- Because the cursor is not isolated during its lifetime, intervening
792+
write operations may cause a document to be returned multiple times.
793+
To handle this situation, see the information on :wiki:`snapshot mode
794+
<How to do Snapshotted Queries in the Mongo Database>`.
792795

793796
- The MongoDB server returns the query results in batches:
794797

795-
- For most queries, the default size of each batch is either 101
796-
documents or enough documents to exceed 1 megabyte, whichever
797-
condition is met first. To override the default size of each batch,
798-
see :method:`cursor.batchSize()` and :method:`cursor.limit()`.
798+
- For most queries, the *first* batch returns 101 documents or just
799+
enough documents to exceed 1 megabyte. Subsequent batch size is 4
800+
megabytes. To override the default size of the batch, see
801+
:method:`cursor.batchSize()` and :method:`cursor.limit()`.
799802

800803
- For queries that include a sort operation *without* an index, the
801804
server must load all the documents in memory to perform the sort
802805
and will return all documents in the first batch.
803806

804-
- Batch size cannot exceed the :ref:`maximum BSON document size
807+
- Batch size will not exceed the :ref:`maximum BSON document size
805808
<limit-bson-document-size>`.
806809

807810
- As you iterate through the cursor and reach the end of the returned
@@ -820,25 +823,27 @@ Consider the following behaviors related to cursors:
820823

821824
myCursor.objsLeftInBatch();
822825

823-
- Batch results may provide performance benefits if you only need to
824-
access a subset of the results, as in the following example which only
825-
requires the first two documents:
826+
- You can use the command :dbcommand:`cursorInfo` to retrieve the
827+
following information on cursors:
826828

827-
.. code-block:: javascript
829+
- total number of open cursors
828830

829-
var myCursor = db.inventory.find();
831+
- size of the client cursors in current use
830832

831-
var myFirstDocument = myCursor.hasNext() ? myCursor.next() : null;
832-
var mySecondDocument = myCursor.hasNext() ? myCursor.next() : null;
833+
- number of timed out cursors since the last server restart
833834

834-
- You can retrieve cursor information, such as the number of open
835-
cursors, using the command :dbcommand:`cursorInfo`, as in the
836-
following example:
835+
Consider the following example:
837836

838837
.. code-block:: javascript
839838

840839
db.runCommand( { cursorInfo: 1 } )
841840

841+
The result from the command returns the following documentation:
842+
843+
.. code-block:: javascript
844+
845+
{ "totalOpen" : <number>, "clientCursors_size" : <number>, "timedOut" : <number>, "ok" : 1 }
846+
842847
.. _read-operations-aggregation:
843848

844849
Aggregation

0 commit comments

Comments
 (0)