Skip to content

Commit 45253ea

Browse files
DOCS-16216 add hint option to distinct command (#4666)
* DOCS-16216 add hint option * DOCS-16216 nit fix * DOCS-16216 internal feedback * DOCS-16216 internal feedback * DOCS-16216 update example * DOCS-16216 fix code example * DOCS-16216 feedback
1 parent 4e0650a commit 45253ea

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

source/reference/command/distinct.txt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ The command has the following syntax:
3737
query: <query>,
3838
readConcern: <read concern document>,
3939
collation: <collation document>,
40-
comment: <any>
40+
comment: <any>,
41+
hint: <string or document>
4142
}
4243
)
4344

@@ -86,7 +87,14 @@ The command takes the following fields:
8687
- .. include:: /includes/extracts/comment-content.rst
8788

8889
.. 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
9098

9199
.. include:: /includes/note-distinct-bson-limit-agg-alternative.rst
92100

@@ -363,3 +371,22 @@ majority of the nodes.
363371
)
364372

365373
.. 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 } } )

source/release-notes/7.1.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ MongoDB 7.1 adds the :parameter:`indexBuildMinAvailableDiskSpaceMB`
5656
parameter, which allows you to set the minimum available disk space
5757
required for index builds.
5858

59+
Specify a query's index using the hint field
60+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61+
62+
Starting in MongoDB 7.1, the hint field is available in the :dbcommand:`distinct` command,
63+
allowing you to specify the query's index.
64+
5965
``serverStatus`` Output Change
6066
------------------------------
6167

0 commit comments

Comments
 (0)