$hint
¶Deprecated since v3.2
Starting in v3.2, the 从v3.2开始,$hint
operator is deprecated in the mongo
shell. $hint
运算符在mongo
shell中不受欢迎。In the 在mongo
shell, use cursor.hint()
instead.mongo
shell中,请改用cursor.hint()
。
The $hint
operator forces the query optimizer to use a specific index to fulfill the query. $hint
运算符强制查询优化器使用特定的索引来完成查询。Specify the index either by the index name or by document.通过索引名称或文档指定索引。
Use 使用$hint
for testing query performance and indexing strategies. $hint
测试查询性能和索引策略。The mongo
shell provides a helper method hint()
for the $hint
operator.mongo
shell为$hint
运算符提供了一个辅助器方法hint()
。
Consider the following operation:考虑以下操作:
This operation returns all documents in the collection named 此操作使用users
using the index on the age
field.age
字段上的索引返回集合中名为users
的所有文档。
You can also specify a hint using either of the following forms:还可以使用以下任一形式指定提示:
Note
When the query specifies the 当查询以以下形式指定$hint
in the following form:$hint
时:
Then, in order to include the 然后,为了包含$explain
option, you must add the $explain
option to the document, as in the following:$explain
选项,必须将$explain
选项添加到文档中,如下所示:
When an index filter exists for the query shape, MongoDB ignores the 当查询形状存在索引筛选器时,MongoDB会忽略$hint
.$hint
。