此版本的文档已存档,不再提供支持。要升级5.0部署,请参阅 MongoDB 6.0升级程序。
$hint$hint操作符强制查询优化器使用特定索引来完成查询。 通过索引名称或文档指定索引。使用
$hint测试查询性能和索引策略。mongosh为 操作符提供了辅助方法hint()$hint。考虑以下操作:
db.users.find().hint( { age: 1 } ) 此操作使用
age字段上的索引返回名为users的collection中的所有文档。您还可以使用以下任一形式指定提示:
db.users.find()._addSpecial( "$hint", { age : 1 } ) db.users.find( { $query: {}, $hint: { age : 1 } } ) 注意