@@ -90,7 +90,9 @@ parameters:
90
90
- document
91
91
- .. _method-find-options:
92
92
93
- .. include:: /includes/find-options-description.rst
93
+ Optional. Specifies additional options for the query. These options
94
+ modify query behavior and how results are returned. For details,
95
+ see :ref:`find-options`.
94
96
95
97
Behavior
96
98
--------
@@ -112,6 +114,13 @@ of the following form:
112
114
113
115
.. include:: /includes/extracts/projection-values-table.rst
114
116
117
+ .. _find-options:
118
+
119
+ Options
120
+ ~~~~~~~
121
+
122
+ .. include:: /includes/find-options-values-table.rst
123
+
115
124
Embedded Field Specification
116
125
````````````````````````````
117
126
@@ -662,8 +671,6 @@ You can also specify embedded fields using the nested form. For example:
662
671
{ _id: 0, name: { last: 1 }, contribs: { $slice: 2 } }
663
672
)
664
673
665
-
666
-
667
674
Use Aggregation Expression
668
675
``````````````````````````
669
676
@@ -991,8 +998,97 @@ Perform the following steps to retrieve the documents accessible to
991
998
992
999
.. include:: /includes/user-roles-system-variable-example-output-jane.rst
993
1000
1001
+ Modify a Query with options
1002
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1003
+
1004
+ The following examples show how you can use the ``options`` field
1005
+ in a ``find()`` query. Use the following
1006
+ :method:`~db.collection.insertMany()` to setup the ``users`` collection:
1007
+
1008
+ .. code-block:: javascript
1009
+ :copyable: true
1010
+
1011
+ db.users.insertMany( [
1012
+ { username: "david", age: 27 },
1013
+ { username: "amanda", age: 25 },
1014
+ { username: "rajiv", age: 32 },
1015
+ { username: "rajiv", age: 90 }
1016
+ ] )
1017
+
1018
+ limit with options
1019
+ ``````````````````
1020
+
1021
+ The following query limits the number of documents in the result set
1022
+ with the ``limit`` options parameter:
1023
+
1024
+ .. code-block:: javascript
1025
+ :copyable: true
1026
+ :emphasize-lines: 4
1027
+
1028
+ db.users.find(
1029
+ { username : "rajiv"}, // query
1030
+ { age : 1 }, // projection
1031
+ { limit : 1 } // options
1032
+ )
1033
+
1034
+ allowDiskUse with options
1035
+ `````````````````````````
1036
+
1037
+ The following query uses the ``options`` parameter to enable
1038
+ ``allowDiskUse``:
1039
+
1040
+ .. code-block:: javascript
1041
+ :copyable: true
1042
+ :emphasize-lines: 4
1043
+
1044
+ db.users.find(
1045
+ { username : "david" },
1046
+ { age : 1 },
1047
+ { allowDiskUse : true }
1048
+ )
1049
+
1050
+ explain with options
1051
+ ````````````````````
1052
+
1053
+ The following query uses the ``options`` parameter to get the
1054
+ ``executionStats`` explain output:
1055
+
1056
+ .. code-block:: javascript
1057
+ :copyable: true
1058
+ :emphasize-lines: 4
1059
+
1060
+ var cursor = db.users.find(
1061
+ { username: "amanda" },
1062
+ { age : 1 },
1063
+ { explain : "executionStats" }
1064
+ )
1065
+ cursor.next()
1066
+
1067
+ Specify Multiple options in a query
1068
+ ```````````````````````````````````
1069
+
1070
+ The following query uses multiple ``options`` in a single query. This
1071
+ query uses ``limit`` set to ``2`` to return only two documents, and
1072
+ ``showRecordId`` set to ``true`` to return the position of the document
1073
+ in the result set:
1074
+
1075
+ .. code-block:: javascript
1076
+ :copyable: true
1077
+ :emphasize-lines: 4-7
1078
+
1079
+ db.users.find(
1080
+ {},
1081
+ { username: 1, age: 1 },
1082
+ {
1083
+ limit: 2,
1084
+ showRecordId: true
1085
+ }
1086
+ )
1087
+
994
1088
Learn More
995
1089
----------
996
1090
997
- To see all available query options, see :node-api-4.0:`FindOptions
998
- </interfaces/findoptions.html>`.
1091
+ - :method:`~db.collection.findOne()`
1092
+ - :method:`~db.collection.findAndModify()`
1093
+ - :method:`~db.collection.findOneAndDelete()`
1094
+ - :method:`~db.collection.findOneAndReplace()`
0 commit comments