-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcursor.toArray.txt
47 lines (29 loc) · 1.19 KB
/
cursor.toArray.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
================
cursor.toArray()
================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. method:: cursor.toArray()
.. include:: /includes/fact-mongosh-shell-method.rst
The :method:`~cursor.toArray()` method returns an array that
contains all the documents from a cursor. The method iterates
completely the cursor, loading all the documents into RAM and
exhausting the cursor.
:returns: An array of documents.
Consider the following example that applies :method:`~cursor.toArray()`
to the cursor returned from the :method:`~db.collection.find()` method:
.. code-block:: javascript
var allProductsArray = db.products.find().toArray();
if (allProductsArray.length > 0) { printjson (allProductsArray[0]); }
The variable ``allProductsArray`` holds the array of documents returned by
:method:`~cursor.toArray()`.
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-all.rst
.. include:: /includes/fact-environments-onprem-only.rst