@@ -4,14 +4,42 @@ db.collection.findOne()
4
4
5
5
.. default-domain:: mongodb
6
6
7
- .. method:: db.collection.findOne(query)
7
+ .. method:: db.collection.findOne(query,projection )
8
8
9
9
:param document query: Optional. A :term:`document` that specifies the :term:`query`
10
10
using the JSON-like syntax and :doc:`query operators
11
11
</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.
12
37
13
38
: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.
15
43
16
44
Returns only one document that satisfies the specified query. If
17
45
multiple documents satisfy the query, this method returns the first
0 commit comments