$indexStats使用$indexStats聚合阶段可获取有关集合中每个索引使用情况的统计信息。例如,以下聚合操作返回有关集合上索引使用情况的统计信息orders:
也可以看看
explain()在executiveStats模式下使用db.collection.explain()或
cursor.explain()方法来返回有关查询过程的统计信息,包括使用的索引,扫描的文档数以及查询处理所花费的时间(以毫秒为单位)。
在allPlansExecution
模式下运行db.collection.explain()或cursor.explain()方法,以查看在计划选择期间收集的部分执行统计信息。
也可以看看
hint()要强制 MongoDB对操作使用特定
db.collection.find()的索引,请使用hint()方法指定索引
。将hint()
方法追加到find()方法上。考虑以下示例:
要查看特定索引的执行统计信息,请db.collection.find()在hint()方法后追加
cursor.explain(),例如:
或者,将hint()方法附加到
db.collection.explain().find():
$natural为该hint()
方法指定操作符,以防止MongoDB使用任何索引:
除了$indexStats聚合阶段外,MongoDB还提供了各种索引统计信息,您在分析数据库的索引使用时可能需要考虑这些统计信息:
在输出serverStatus: |
|
在输出collStats: |
|
在输出dbStats: |