4
4
Retrieve Data
5
5
=============
6
6
7
+ .. facet::
8
+ :name: genre
9
+ :values: reference
10
+
11
+ .. meta::
12
+ :keywords: node.js, code example, find one, find many
13
+
7
14
.. contents:: On this page
8
15
:local:
9
16
:backlinks: none
@@ -72,8 +79,8 @@ see the :ref:`node-fundamentals-query-document` guide.
72
79
73
80
.. code-block:: javascript
74
81
75
- await myColl.find(); // no query
76
- await myColl.find({}); // empty query
82
+ myColl.find(); // no query
83
+ myColl.find({}); // empty query
77
84
78
85
If you don't pass a query or pass an empty query
79
86
to the ``findOne()`` method, the operation returns a single
@@ -82,7 +89,7 @@ see the :ref:`node-fundamentals-query-document` guide.
82
89
You can specify options in a find operation even when you pass an
83
90
empty query. For example, the following code shows how you can
84
91
specify a projection as an option while executing a find operation
85
- with an empty query parameter:
92
+ that receives an empty query parameter:
86
93
87
94
.. code-block:: javascript
88
95
@@ -92,10 +99,13 @@ see the :ref:`node-fundamentals-query-document` guide.
92
99
93
100
const findResult = await myColl.findOne({}, options);
94
101
95
- If you resolve the ``Promise`` returned by ``find()``, you receive
96
- a reference to a ``Cursor`` with which you can navigate matched documents.
97
- If you resolve the ``Promise`` returned by ``findOne()``, you receive the
98
- matching document or ``null`` if there are no matches.
102
+ For more information about projecting document fields, see the
103
+ :ref:`node-fundamentals-project` guide.
104
+
105
+ The ``find()`` method returns a ``Cursor`` instance from which you can
106
+ access the matched documents. The ``findOne()`` method returns a ``Promise``
107
+ instance, which you can resolve to access either the matching document or
108
+ a ``null`` value if there are no matches.
99
109
100
110
.. example::
101
111
@@ -129,8 +139,20 @@ matching document or ``null`` if there are no matches.
129
139
...
130
140
]
131
141
132
- See the :ref:`find() <node-usage-find>` and :ref:`findOne()
133
- <node-usage-findone>` for fully-runnable examples.
142
+ Additional Information
143
+ ~~~~~~~~~~~~~~~~~~~~~~
144
+
145
+ For runnable code examples that demonstrate find operations, see the following
146
+ usage examples:
147
+
148
+ - :ref:`node-usage-findone`
149
+ - :ref:`node-usage-find`
150
+
151
+ For more information about the ``findOne()`` and ``find()`` methods, see the
152
+ following Server manual documentation:
153
+
154
+ - :manual:`findOne() </reference/method/db.collection.findOne/>`
155
+ - :manual:`find() </reference/method/db.collection.find/>`
134
156
135
157
Aggregate Data from Documents
136
158
-----------------------------
@@ -173,8 +195,12 @@ group, and arrange the result data from a collection.
173
195
{ _id: 'created', count: 9 }
174
196
]
175
197
176
- See the {+mdb-server+} manual pages on :manual:`aggregation </aggregation>`
177
- for more information on how to construct an aggregation pipeline.
198
+ Additional Information
199
+ ~~~~~~~~~~~~~~~~~~~~~~
200
+
201
+ For more information on how to construct an aggregation pipeline, see
202
+ the :ref:`node-aggregation` guide or :manual:`Aggregation Operations </aggregation>`
203
+ in the Server manual.
178
204
179
205
.. _node-fundamentals-watch:
180
206
@@ -200,8 +226,11 @@ data whenever write operations are executed on the collection.
200
226
:start-after: start watch crud example
201
227
:end-before: end watch crud example
202
228
203
- For a runnable example of the ``watch()`` method using the NodeJS driver, see
204
- the :ref:`change streams <node-usage-watch>` usage example.
229
+ Additional Information
230
+ ~~~~~~~~~~~~~~~~~~~~~~
231
+
232
+ For a runnable example of the ``watch()`` method, see the
233
+ :ref:`Watch for Changes <node-usage-watch>` usage example.
205
234
206
235
.. _node-retrieve-instruqt-lab:
207
236
0 commit comments