File tree Expand file tree Collapse file tree 2 files changed +36
-6
lines changed Expand file tree Collapse file tree 2 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -732,23 +732,25 @@ information on cursor methods.
732
732
Iterator Index
733
733
~~~~~~~~~~~~~~
734
734
735
- In the :program:`mongo` shell, you can use the `` toArray()`` method to
736
- iterate the cursor and return the documents in an array, as in the
737
- following:
735
+ In the :program:`mongo` shell, you can use the :method:` toArray()
736
+ <cursor.toArray()>` method to iterate the cursor and return the
737
+ documents in an array, as in the following:
738
738
739
739
.. code-block:: javascript
740
740
741
741
var myCursor = db.inventory.find( { type: 'food' } );
742
742
var documentArray = myCursor.toArray();
743
743
var myDocument = documentArray[3];
744
744
745
- The ``toArray()`` method loads into RAM all documents returned by the
746
- cursor; the ``toArray()`` method exhausts the cursor.
745
+ The :method:`toArray() <cursor.toArray()>` method loads into RAM all
746
+ documents returned by the cursor; the :method:`toArray()
747
+ <cursor.toArray()>` method exhausts the cursor.
747
748
748
749
Additionally, some :doc:`drivers </applications/drivers>` provide
749
750
access to the documents by using an index on the cursor (i.e.
750
751
``cursor[index]``). This is a shortcut for first calling the
751
- ``toArray()`` method and then using an index on the resulting array.
752
+ :method:`toArray() <cursor.toArray()>` method and then using an index
753
+ on the resulting array.
752
754
753
755
Consider the following example:
754
756
Original file line number Diff line number Diff line change
1
+ ================
2
+ cursor.toArray()
3
+ ================
4
+
5
+ .. default-domain:: mongodb
6
+
7
+ .. method:: cursor.toArray()
8
+
9
+ The :method:`toArray() <cursor.toArray()>` method iterates a cursor
10
+ completely to retrieve the documents and return these documents in
11
+ an array. The :method:`toArray() <cursor.toArray()>` method loads
12
+ into RAM all documents returned by the cursor and exhausts the
13
+ cursor.
14
+
15
+ :returns: An array of documents.
16
+
17
+ Consider the following example that applies :method:`toArray()
18
+ <cursor.toArray()>` to the cursor returned from the :method:`find()
19
+ <db.collection.find()>` method:
20
+
21
+ .. code-block:: javascript
22
+
23
+ var docArray = db.products.find().toArray();
24
+
25
+ if (docArray.length > 0) { printjson (docArray[0]); }
26
+
27
+ The variable ``docArray`` holds the array of documents returned by
28
+ :method:`toArray() <cursor.toArray()>`.
You can’t perform that action at this time.
0 commit comments