@@ -80,7 +80,9 @@ parameters:
80
80
- document
81
81
- .. _method-find-options:
82
82
83
- .. include:: /includes/find-options-description.rst
83
+ Optional. Specifies additional options for the query. These options
84
+ modify query behavior and how results are returned. For details,
85
+ see :ref:`find-options`.
84
86
85
87
Behavior
86
88
--------
@@ -102,6 +104,13 @@ of the following form:
102
104
103
105
.. include:: /includes/extracts/projection-values-table.rst
104
106
107
+ .. _find-options:
108
+
109
+ Options
110
+ ~~~~~~~
111
+
112
+ .. include:: /includes/find-options-values-table.rst
113
+
105
114
Embedded Field Specification
106
115
````````````````````````````
107
116
@@ -620,8 +629,6 @@ You can also specify embedded fields using the nested form. For example:
620
629
{ _id: 0, name: { last: 1 }, contribs: { $slice: 2 } }
621
630
)
622
631
623
-
624
-
625
632
Use Aggregation Expression
626
633
``````````````````````````
627
634
@@ -949,8 +956,97 @@ Perform the following steps to retrieve the documents accessible to
949
956
950
957
.. include:: /includes/user-roles-system-variable-example-output-jane.rst
951
958
959
+ Modify a Query with options
960
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
961
+
962
+ The following examples show how you can use the ``options`` field
963
+ in a ``find()`` query. Use the following
964
+ :method:`~db.collection.insertMany()` to setup the ``users`` collection:
965
+
966
+ .. code-block:: javascript
967
+ :copyable: true
968
+
969
+ db.users.insertMany( [
970
+ { username: "david", age: 27 },
971
+ { username: "amanda", age: 25 },
972
+ { username: "rajiv", age: 32 },
973
+ { username: "rajiv", age: 90 }
974
+ ] )
975
+
976
+ limit with options
977
+ ``````````````````
978
+
979
+ The following query limits the number of documents in the result set
980
+ with the ``limit`` options parameter:
981
+
982
+ .. code-block:: javascript
983
+ :copyable: true
984
+ :emphasize-lines: 4
985
+
986
+ db.users.find(
987
+ { username : "rajiv"}, // query
988
+ { age : 1 }, // projection
989
+ { limit : 1 } // options
990
+ )
991
+
992
+ allowDiskUse with options
993
+ `````````````````````````
994
+
995
+ The following query uses the ``options`` parameter to enable
996
+ ``allowDiskUse``:
997
+
998
+ .. code-block:: javascript
999
+ :copyable: true
1000
+ :emphasize-lines: 4
1001
+
1002
+ db.users.find(
1003
+ { username : "david" },
1004
+ { age : 1 },
1005
+ { allowDiskUse : true }
1006
+ )
1007
+
1008
+ explain with options
1009
+ ````````````````````
1010
+
1011
+ The following query uses the ``options`` parameter to get the
1012
+ ``executionStats`` explain output:
1013
+
1014
+ .. code-block:: javascript
1015
+ :copyable: true
1016
+ :emphasize-lines: 4
1017
+
1018
+ var cursor = db.users.find(
1019
+ { username: "amanda" },
1020
+ { age : 1 },
1021
+ { explain : "executionStats" }
1022
+ )
1023
+ cursor.next()
1024
+
1025
+ Specify Multiple options in a query
1026
+ ```````````````````````````````````
1027
+
1028
+ The following query uses multiple ``options`` in a single query. This
1029
+ query uses ``limit`` set to ``2`` to return only two documents, and
1030
+ ``showRecordId`` set to ``true`` to return the position of the document
1031
+ in the result set:
1032
+
1033
+ .. code-block:: javascript
1034
+ :copyable: true
1035
+ :emphasize-lines: 4-7
1036
+
1037
+ db.users.find(
1038
+ {},
1039
+ { username: 1, age: 1 },
1040
+ {
1041
+ limit: 2,
1042
+ showRecordId: true
1043
+ }
1044
+ )
1045
+
952
1046
Learn More
953
1047
----------
954
1048
955
- To see all available query options, see :node-api-4.0:`FindOptions
956
- </interfaces/findoptions.html>`.
1049
+ - :method:`~db.collection.findOne()`
1050
+ - :method:`~db.collection.findAndModify()`
1051
+ - :method:`~db.collection.findOneAndDelete()`
1052
+ - :method:`~db.collection.findOneAndReplace()`
0 commit comments