@@ -37,7 +37,8 @@ The command has the following syntax:
37
37
query: <query>,
38
38
readConcern: <read concern document>,
39
39
collation: <collation document>,
40
- comment: <any>
40
+ comment: <any>,
41
+ hint: <string or document>
41
42
}
42
43
)
43
44
@@ -86,7 +87,14 @@ The command takes the following fields:
86
87
- .. include:: /includes/extracts/comment-content.rst
87
88
88
89
.. versionadded:: 4.4
89
-
90
+
91
+ * - ``hint``
92
+ - string or document
93
+ - Optional. Specify the index name, either as a string or a document. If specified,
94
+ the query planner only considers plans using the hinted index. For more details,
95
+ see :ref:`Specify an Index <index-example>`.
96
+
97
+ .. versionadded:: 7.1
90
98
91
99
.. include:: /includes/note-distinct-bson-limit-agg-alternative.rst
92
100
@@ -363,3 +371,22 @@ majority of the nodes.
363
371
)
364
372
365
373
.. include:: /includes/usage-read-concern-majority.rst
374
+
375
+ .. _index-example:
376
+
377
+ Specify an Index
378
+ ~~~~~~~~~~~~~~~~
379
+
380
+ You can specify an index name or pattern using the hint option.
381
+
382
+ To specify a hint based on an index name:
383
+
384
+ .. code-block:: javascript
385
+
386
+ db.runCommand ( { distinct: "inventory", key: "dept", hint: "sizes" } )
387
+
388
+ To specify a hint based on an index pattern:
389
+
390
+ .. code-block:: javascript
391
+
392
+ db.runCommand ( { distinct: "inventory", key: "dept", hint: { sizes: 1 } } )
0 commit comments