On this page本页内容
$indexStats
$indexStats
获取索引访问信息¶Use the 使用$indexStats
aggregation stage to get statistics regarding the use of each index for a collection. $indexStats
聚合阶段获取有关集合中每个索引使用情况的统计信息。For example, the following aggregation operation returns statistics on the index use on the 例如,以下聚合操作返回有关orders集合上使用的索引的统计信息:orders
collection:
See also参阅
explain()
explain()
的查询计划¶Use the 在db.collection.explain()
or the cursor.explain()
method in executionStats mode to return statistics about the query process, including the index used, the number of documents scanned, and the time the query takes to process in milliseconds.executionStats
模式下使用db.collection.explain()
或cursor.explain()
方法返回有关查询过程的统计信息,包括使用的索引、扫描的文档数以及查询处理所需的时间(以毫秒为单位)。
Run 在db.collection.explain()
or the cursor.explain()
method in allPlansExecution mode to view partial execution statistics collected during plan selection.allPlansExecution
模式下运行db.collection.explain()
或cursor.explain()
方法,以查看在计划选择期间收集的部分执行统计信息。
See also参阅
hint()
hint()
一起使用¶To force MongoDB to use a particular index for a 要强制MongoDB为db.collection.find()
operation, specify the index with the hint()
method. db.collection.find()
操作使用特定索引,请使用hint()
方法指定索引。Append the 将hint()
method to the find()
method. hint()
方法附加到find()
方法。Consider the following example:考虑下面的例子:
To view the execution statistics for a specific index, append to the 要查看特定索引的执行统计信息,请在db.collection.find()
the hint()
method followed by cursor.explain()
, e.g.:db.collection.find()
后附加hint()
方法,后跟cursor.explain()
,例如:
Or, append 或者,将hint()
method to db.collection.explain().find()
:hint()
方法附加到db.collection.explain().find()
:
Specify the 为$natural
operator to the hint()
method to prevent MongoDB from using any index:hint()
方法指定$natural
运算符,以防止MongoDB使用任何索引:
In addition to the 除了$indexStats
aggregation stage, MongoDB provides various index statistics that you may want to consider when analyzing index use for your database:$indexStats
聚合阶段,MangGDB还提供了在分析数据库的索引使用时可能要考虑的各种索引统计信息:
In the output of serverStatus : |
|
In the output of collStats : |
|
In the output of dbStats : |