- Reference >
- Operators >
- Query Modifiers >
- $hint
$hint¶
-
$hint
¶ Deprecated since v3.2
Starting in v3.2, the
$hint
operator is deprecated in themongo
shell. In themongo
shell, usecursor.hint()
instead.The
$hint
operator 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
$hint
for testing query performance and indexing strategies. Themongo
shell provides a helper methodhint()
for the$hint
operator.Consider the following operation:
This operation returns all documents in the collection named
users
using the index on theage
field.You can also specify a hint using either of the following forms:
Note
When the query specifies the
$hint
in the following form:Then, in order to include the
$explain
option, you must add the$explain
option to the document, as in the following:When an index filter exists for the query shape, MongoDB ignores the
$hint
.