- Reference >
- Operators >
- Query Modifiers >
- $hint
$hint¶
-
$hint¶ Note
- Deprecated in the
mongoShell since v3.2 - Starting in v3.2, the
$hintoperator is deprecated in themongoshell. In themongoshell, usecursor.hint()instead.
The
$hintoperator forces the query optimizer to use a specific index to fulfill the query. Specify the index either by the index name or by document.Use
$hintfor testing query performance and indexing strategies. Themongoshell provides a helper methodhint()for the$hintoperator.Consider the following operation:
This operation returns all documents in the collection named
usersusing the index on theagefield.You can also specify a hint using either of the following forms:
Note
When the query specifies the
$hintin the following form:Then, in order to include the
$explainoption, you must add the$explainoption to the document, as in the following:When an index filter exists for the query shape, MongoDB ignores the
$hint.- Deprecated in the