@@ -6,19 +6,19 @@ Find a Document
6
6
7
7
.. note::
8
8
If you specify a callback method, ``findOne()`` returns nothing. If you do
9
- not specify one, this method returns a
10
- :mdn:`Promise <Web/JavaScript/Reference/Global_Objects/Promise>` that
11
- resolves to the result object when it completes. For more information on
12
- the result object type, see the
13
- :node-api:`API documentation <Collection.html#~resultCallback>` .
14
-
15
- You can query for a single document in a collection with
16
- the ``collection.findOne()`` method. The ``findOne()`` method uses a query
9
+ not specify one, this method returns a ``Promise`` that resolves to the
10
+ result object when it completes. See our guide on :doc:`Promises and
11
+ Callbacks </fundamentals/promises>` for more information, or the
12
+ :node-api:`API documentation <Collection.html#~resultCallback>` for
13
+ information on the result object .
14
+
15
+ You can query for a single document in a collection with the
16
+ ``collection.findOne()`` method. The ``findOne()`` method uses a query
17
17
document that you provide to match only the subset of the documents in the
18
- collection that match the query. If you don't provide a query document ( or if
19
- you provide an empty document) , MongoDB matches all documents in the
20
- collection. However, the operation only returns the first matched document.
21
- For more information on querying MongoDB, see our
18
+ collection that match the query. If you don't provide a query document or if
19
+ you provide an empty document, MongoDB matches all documents in the
20
+ collection. The ``findOne()`` operation only returns the first matched
21
+ document. For more information on querying MongoDB, see our
22
22
:doc:`documentation on query documents </fundamentals/crud/query-document>`.
23
23
24
24
You can also define additional query options such as
@@ -33,7 +33,7 @@ Example
33
33
-------
34
34
35
35
The following snippet finds a single document from the ``movies``
36
- collection. It uses the following:
36
+ collection. It uses the following parameters :
37
37
38
38
- A **query document** that configures the query to return only
39
39
movies with the title of exactly the text ``'The Room'``.
@@ -50,5 +50,12 @@ collection. It uses the following:
50
50
51
51
.. literalinclude:: /code-snippets/usage-examples/findOne.js
52
52
:language: javascript
53
- :emphasize-lines: 26
54
- :linenos:
53
+ :dedent: 4
54
+
55
+ If you run the example above, you should see a result that resembles the
56
+ following:
57
+
58
+ .. code-block:: javascript
59
+
60
+ { title: 'The Room', imdb: { rating: 3.5, votes: 25673, id: 368226 } }
61
+
0 commit comments