On this page本页内容
$indexStats
¶New in version 3.2.版本3.2中的新功能。
Returns statistics regarding the use of each index for the collection. 返回有关集合中每个索引使用情况的统计信息。If running with access control, the user must have privileges that include 如果使用访问控制运行,用户必须具有包含indexStats
action.indexStats
操作的权限。
The $indexStats
stage takes an empty document and has the following syntax:$indexStats
阶段接受一个空文档,并具有如下语法:
For each index, the return document includes the following fields:对于每个索引,退货文档包括以下字段:
name |
|
key |
|
host |
|
accesses |
|
shard |
|
spec |
|
building |
|
Statistics for an index will be reset on 在mongod
restart or index drop and recreation.mongod
重新启动或索引删除和重新创建时,索引的统计信息将被重置。
The statistics reported by the accesses field only includes index access driven by user requests. accesses字段报告的统计信息仅包括由用户请求驱动的索引访问。It does not include internal operations like deletion via TTL Indexes or chunk split and migration operations.它不包括内部操作,如通过TTL索引删除或区块分割和迁移操作。
$indexStats
$indexStats
is not allowed in transactions.$indexStats
。For example, a collection 例如,orders
contains the following documents:orders
集合包含以下文档:
Create the following two indexes on the collection:在集合上创建以下两个索引:
Run some queries against the collection:对集合运行一些查询:
To view statistics on the index use on the 要查看orders
collection, run the following aggregation operation:orders
集合上索引使用的统计信息,请运行以下聚合操作:
The operation returns a document that contains usage statistics for each index:该操作返回一个文档,其中包含每个索引的使用统计信息: