Skip to content

Commit 8ef2d1c

Browse files
committed
DOCS-1049 add projection argument in findOne method ref
1 parent b588599 commit 8ef2d1c

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

source/reference/method/db.collection.find.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ db.collection.find()
4242

4343
The ``projection`` cannot contain both include and exclude
4444
specifications except for the exclusion of the ``_id`` field.
45+
46+
Omit the ``projection`` parameter to return **all** the fields in
47+
the matching documents.
4548

4649
:returns:
4750

48-
A :term:`cursor` to the documents that match
49-
the ``query`` criteria and contain the ``projection`` fields.
51+
A :term:`cursor` to the documents that match the ``query``
52+
criteria. If the ``projection`` argument is specified, the
53+
matching documents contain only the ``projection`` fields, and
54+
the ``_id`` field if you do not explicitly exclude the ``_id``
55+
field.
5056

5157
.. note::
5258

source/reference/method/db.collection.findOne.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,42 @@ db.collection.findOne()
44

55
.. default-domain:: mongodb
66

7-
.. method:: db.collection.findOne(query)
7+
.. method:: db.collection.findOne(query,projection)
88

99
:param document query: Optional. A :term:`document` that specifies the :term:`query`
1010
using the JSON-like syntax and :doc:`query operators
1111
</reference/operators>`.
12+
:param document projection:
13+
14+
Optional. Controls the fields to return, or the
15+
:term:`projection`. The ``projection`` argument will
16+
resemble the following prototype:
17+
18+
.. code-block:: javascript
19+
20+
{ field1: boolean, field2: boolean ... }
21+
22+
The ``boolean`` can take the following include or exclude
23+
values:
24+
25+
- ``1`` or ``true`` to include. The
26+
:method:`~db.collection.findOne()` method always includes
27+
the :term:`_id` field even if the field is not explicitly
28+
stated to return in the :term:`projection` parameter.
29+
30+
- ``0`` or ``false`` to exclude.
31+
32+
The ``projection`` cannot contain both include and exclude
33+
specifications except for the exclusion of the ``_id`` field.
34+
35+
Omit the ``projection`` parameter to return **all** the fields in
36+
the matching documents.
1237

1338
:returns: One document that satisfies the query specified as the
14-
argument to this method.
39+
argument to this method. If the ``projection`` argument is
40+
specified, the returned document contains only the
41+
``projection`` fields, and the ``_id`` field if you do not
42+
explicitly exclude the ``_id`` field.
1543

1644
Returns only one document that satisfies the specified query. If
1745
multiple documents satisfy the query, this method returns the first

0 commit comments

Comments
 (0)