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