On this page
$hint
$hint
Note
从 v3.2 开始在
mongo
Shell 中弃用从 v3.2 开始,$hint运算符在mongo shell 中已弃用。在mongoShell 中,改用cursor.hint()。
$hint运算符强制query optimizer使用特定索引来完成查询。通过索引名称或文档指定索引。
使用$hint测试查询性能和索引策略。 mongo shell 为$hint运算符提供了一个辅助方法hint()。
请考虑以下操作:
db.users.find().hint( { age: 1 } )
此操作使用age
字段上的索引返回名为users
的集合中的所有文档。
您还可以使用以下两种形式之一指定提示:
db.users.find()._addSpecial( "$hint", { age : 1 } )
db.users.find( { $query: {}, $hint: { age : 1 } } )
Note
当查询形状存在index filter时,MongoDB 将忽略$hint。