@@ -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
@@ -902,5 +909,97 @@ Output:
902
909
903
910
[ { flavor: 'chocolate' } ]
904
911
905
- To see all available query options, see :node-api-4.0:`FindOptions
906
- </interfaces/findoptions.html>`.
912
+ Modify a Query with options
913
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
914
+
915
+ The following examples show how you can use the ``options`` field
916
+ in a ``find()`` query. Use the following
917
+ :method:`~db.collection.insertMany()` to setup the ``users`` collection:
918
+
919
+ .. code-block:: javascript
920
+ :copyable: true
921
+
922
+ db.users.insertMany( [
923
+ { username: "david", age: 27 },
924
+ { username: "amanda", age: 25 },
925
+ { username: "rajiv", age: 32 },
926
+ { username: "rajiv", age: 90 }
927
+ ] )
928
+
929
+ limit with options
930
+ ``````````````````
931
+
932
+ The following query limits the number of documents in the result set
933
+ with the ``limit`` options parameter:
934
+
935
+ .. code-block:: javascript
936
+ :copyable: true
937
+ :emphasize-lines: 4
938
+
939
+ db.users.find(
940
+ { username : "rajiv"}, // query
941
+ { age : 1 }, // projection
942
+ { limit : 1 } // options
943
+ )
944
+
945
+ allowDiskUse with options
946
+ `````````````````````````
947
+
948
+ The following query uses the ``options`` parameter to enable
949
+ ``allowDiskUse``:
950
+
951
+ .. code-block:: javascript
952
+ :copyable: true
953
+ :emphasize-lines: 4
954
+
955
+ db.users.find(
956
+ { username : "david" },
957
+ { age : 1 },
958
+ { allowDiskUse : true }
959
+ )
960
+
961
+ explain with options
962
+ ````````````````````
963
+
964
+ The following query uses the ``options`` parameter to get the
965
+ ``executionStats`` explain output:
966
+
967
+ .. code-block:: javascript
968
+ :copyable: true
969
+ :emphasize-lines: 4
970
+
971
+ var cursor = db.users.find(
972
+ { username: "amanda" },
973
+ { age : 1 },
974
+ { explain : "executionStats" }
975
+ )
976
+ cursor.next()
977
+
978
+ Specify Multiple options in a query
979
+ ```````````````````````````````````
980
+
981
+ The following query uses multiple ``options`` in a single query. This
982
+ query uses ``limit`` set to ``2`` to return only two documents, and
983
+ ``showRecordId`` set to ``true`` to return the position of the document
984
+ in the result set:
985
+
986
+ .. code-block:: javascript
987
+ :copyable: true
988
+ :emphasize-lines: 4-7
989
+
990
+ db.users.find(
991
+ {},
992
+ { username: 1, age: 1 },
993
+ {
994
+ limit: 2,
995
+ showRecordId: true
996
+ }
997
+ )
998
+
999
+ Learn More
1000
+ ----------
1001
+
1002
+ - :method:`~db.collection.findOne()`
1003
+ - :method:`~db.collection.findAndModify()`
1004
+ - :method:`~db.collection.findOneAndDelete()`
1005
+ - :method:`~db.collection.findOneAndReplace()`
0 commit comments