collStats
On this page本页内容
Definition定义
collStats
Deprecated since version 6.2.自版本6.2以来已弃用。In versions 6.2 and later use the在6.2及更高版本中,使用$collStats
aggregation stage.$collStats
聚合阶段。ThecollStats
command returns a variety of storage statistics for a given collection.collStats
命令返回给定集合的各种存储统计信息。Use the使用$collStats
aggregation stage instead of thecollStats
command and itsmongosh
helper methoddb.collection.stats()
.$collStats
聚合阶段,而不是collStats
命令及其mongosh
辅助方法db.collection.stats()
。TipIn在mongosh
, this command can also be run through thestats()
helper method.mongosh
中,这个命令也可以通过stats()
助手方法运行。Specific fields in thecollStats
output can be accessed using thedataSize()
,estimatedDocumentCount()
,isCapped()
,latencyStats()
,storageSize()
,totalIndexSize()
, andtotalSize()
helper methods.collStats
输出中的特定字段可以使用dataSize()
、estimatedDocumentCount()
、isCapped()
、latencyStats()
、storageSize()
、totalIndexSize()
和totalSize()
辅助方法访问。Helper methods are convenient for助手方法对mongosh
users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.mongosh
用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。如果不需要方便,或者需要额外的返回字段,请使用数据库命令。To run要运行collStats
, use thedb.runCommand( { <command> } )
method.collStats
,请使用db.runCommand( { <command> } )
方法。
Syntax语法
The command has the following syntax:该命令具有以下语法:
db.runCommand(
{
collStats: <string>,
scale: <int>
}
)
Command Fields命令字段
The command takes the following fields:该命令包含以下字段:
collStats | string | |
scale | int | scale value of 1024 .1024 的scale 值。1023.999 , MongoDB uses 1023 as the scale factor.1023.999 ,MongoDB将使用1023 作为比例因子。 |
Behavior行为
Redaction修改
When using Queryable Encryption, 使用可查询加密时,$collStats
output redacts certain information for encrypted collections:$collStats
输出会对加密集合的某些信息进行编辑:
The output omits输出省略"queryExecStats"
The output omits输出省略"latencyStats"
The output redacts输出对"WiredTiger"
, if present, to include only theurl
field."WiredTiger"
(如果存在)进行编辑,以仅包括url
字段。
Scaled Sizes缩放尺寸
Unless otherwise specified by the metric name (such as 除非度量名称另有规定(例如“缓存中当前的字节数”),否则与大小相关的值以字节为单位显示,并且可以按比例覆盖。"bytes currently in the cache"
), values related to size are displayed in bytes and can be overridden by scale
.
The scale factor rounds the affected size values to whole numbers.比例因子将受影响的大小值四舍五入为整数。
Accuracy after Unexpected Shutdown意外停机后的准确性
After an unclean shutdown of a 在使用Wired Tiger存储引擎不干净地关闭mongod
using the Wired Tiger storage engine, size statistics reported by collStats
may be inaccurate.mongod
之后,collStats
报告的大小统计数据可能不准确。
The amount of drift depends on the number of insert, update, or delete operations performed between the last checkpoint and the unclean shutdown. Checkpoints usually occur every 60 seconds. 漂移量取决于在最后一个检查点和非干净关闭之间执行的插入、更新或删除操作的数量。检查点通常每60秒出现一次。However, 然而,使用非默认mongod
instances running with non-default --syncdelay
settings may have more or less frequent checkpoints.--syncdelay
设置运行的mongod
实例可能或多或少有频繁的检查点。
Run 对validate
on each collection on the mongod
to restore statistics after an unclean shutdown.mongod
上的每个集合运行validate
,以在不干净的关闭后恢复统计信息。
After an unclean shutdown:不干净关机后:
In-Progress Indexes进行中索引
collStats
includes information on indexes currently being built. 包括有关当前正在生成的索引的信息。For details, see:有关详细信息,请参阅:
Replica Set Member State Restriction副本集成员状态限制
Starting in MongoDB 4.4, to run on a replica set member, 从MongoDB 4.4开始,要在副本集成员上运行,collStats
operations require the member to be in PRIMARY
or SECONDARY
state. If the member is in another state, such as STARTUP2
, the operation errors.collStats
操作要求该成员处于PRIMARY
或SECONDARY
状态。如果成员处于其他状态,例如STARTUP2
,则操作将出错。
In previous versions, the operations also run when the member is in 在以前的版本中,成员处于STARTUP2
. The operations wait until the member transitioned to RECOVERING
.STARTUP2
时也会运行这些操作。操作将等待,直到成员转换到RECOVERING
。
Non-Existent Collections不存在的集合
If you run 如果对不存在的集合运行collStats
for a non-existent collection, then depending on your database implementation, collStats
might return 0
values in the output fields instead of returning an error.collStats
,那么根据数据库实现的不同,collStat可能会在输出字段中返回0值,而不是返回错误。
For example:例如:
db.runCommand( { collStats : "nonExistentCollection" } )
Example output with 字段中包含0
values in the fields:0
值的输出示例:
{
ns: 'test.nonExistentCollection',
size: 0,
count: 0,
...
}
Example实例
The following operation runs the 以下操作在collStats
command on the restaurants
collection, specifying a scale of 1024
bytes:restaurants
集合上运行collStats
命令,指定1024
字节的小数位数:
db.runCommand( { collStats : "restaurants", scale: 1024 } )
The following document provides a representation of the 以下文档提供了collStats
output. collStats
输出的表示形式。Depending on the configuration of your collection and the storage engine, the output fields may vary.根据集合和存储引擎的配置,输出字段可能会有所不同。
{
"ns" : <string>,
"size" : <number>,
"timeseries" : {
"bucketsNs" : <bucketName>,
"bucketCount" : <number>,
"avgBucketSize" : <number>,
"numBucketInserts" : <number>,
"numBucketUpdates" : <number>,
"numBucketsOpenedDueToMetadata" : <number>,
"numBucketsClosedDueToCount" : <number>,
"numBucketsClosedDueToSize" : <number>,
"numBucketsClosedDueToTimeForward" : <number>,
"numBucketsClosedDueToTimeBackward" : <number>,
"numBucketsClosedDueToMemoryThreshold" : <number>,
"numCommits" : <number>,
"numWaits" : <number>,
"numMeasurementsCommitted" : <number>,
"avgNumMeasurementsPerCommit": <number>
},
"count" : <number>,
"avgObjSize" : <number>,
"numOrphanDocs" : <number>, // Available starting in MongoDB 6.0
"storageSize" : <number>,
"freeStorageSize" : <number>,
"capped" : <boolean>,
"max" : <number>,
"maxSize" : <number>,
"wiredTiger" : {
"metadata" : {
"formatVersion" : <num>
},
"creationString" : <string>
"type" : <string>,
"uri" : <string>,
"LSM" : {
"bloom filter false positives" : <number>,
"bloom filter hits" : <number>,
"bloom filter misses" : <number>,
"bloom filter pages evicted from cache" : <number>,
"bloom filter pages read into cache" : <number>,
"bloom filters in the LSM tree" : <number>,
"total size of bloom filters" : <number>,
"chunks in the LSM tree" : <number>,
"highest merge generation in the LSM tree" : <number>,
"queries that could have benefited from a Bloom filter that did not exist" : <number>,
"sleep for LSM checkpoint throttle" : <number>,
"sleep for LSM merge throttle" : <number>
"total size of bloom filters" : <number>
},
"block-manager" : {
"allocations requiring file extension" : <number>,
"blocks allocated" : <number>,
"blocks freed" : <number>,
"checkpoint size" : <number>,
"file allocation unit size" : <number>,
"file bytes available for reuse" : <number>,
"file magic number" : <number>,
"file major version number" : <number>,
"file size in bytes" : <number>,
"minor version number" : <number>
},
"btree" : {
"btree checkpoint generation" : <number>,
"column-store fixed-size leaf pages" : <number>,
"column-store internal pages" : <number>,
"column-store variable-size RLE encoded values" : <number>,
"column-store variable-size deleted values" : <number>,
"column-store variable-size leaf pages" : <number>,
"fixed-record size" : <number>,
"maximum internal page key size" : <number>,
"maximum internal page size" : <number>,
"maximum leaf page key size" : <number>,
"maximum leaf page size" : <number>,
"maximum leaf page value size" : <number>,
"maximum tree depth" : <number>,
"number of key/value pairs" : <number>,
"overflow pages" : <number>,
"pages rewritten by compaction" : <number>,
"row-store empty values" : <number>,
"row-store internal pages" : <number>,
"row-store leaf pages" : <number>
},
"cache" : {
"bytes currently in the cache" : <number>,
"bytes dirty in the cache cumulative" : <number>,
"bytes read into cache" : <number>,
"bytes written from cache" : <number>,
"checkpoint blocked page eviction" : <number>,
"data source pages selected for eviction unable to be evicted" : <number>,
"eviction walk passes of a file" : <number>,
"eviction walk target pages histogram - 0-9" : <number>,
"eviction walk target pages histogram - 10-31" : <number>,
"eviction walk target pages histogram - 128 and higher" : <number>,
"eviction walk target pages histogram - 32-63" : <number>,
"eviction walk target pages histogram - 64-128" : <number>,
"eviction walks abandoned" : <number>,
"eviction walks gave up because they restarted their walk twice" : <number>,
"eviction walks gave up because they saw too many pages and found no candidates" : <number>,
"eviction walks gave up because they saw too many pages and found too few candidates" : <number>,
"eviction walks reached end of tree" : <number>,
"eviction walks started from root of tree" : <number>,
"eviction walks started from saved location in tree" : <number>,
"hazard pointer blocked page eviction" : <number>,
"in-memory page passed criteria to be split" : <number>,
"in-memory page splits" : <number>,
"internal pages evicted" : <number>,
"internal pages split during eviction" : <number>,
"leaf pages split during eviction" : <number>,
"modified pages evicted" : <number>,
"overflow pages read into cache" : <number>,
"page split during eviction deepened the tree" : <number>,
"page written requiring cache overflow records" : <number>,
"pages read into cache" : <number>,
"pages read into cache after truncate" : <number>,
"pages read into cache after truncate in prepare state" : <number>,
"pages read into cache requiring cache overflow entries" : <number>,
"pages requested from the cache" : <number>,
"pages seen by eviction walk" : <number>,
"pages written from cache" : <number>,
"pages written requiring in-memory restoration" : <number>,
"tracked dirty bytes in the cache" : <number>,
"unmodified pages evicted" : <number>
},
"cache_walk" : {
"Average difference between current eviction generation when the page was last considered" : <number>,
"Average on-disk page image size seen" : <number>,
"Average time in cache for pages that have been visited by the eviction server" : <number>,
"Average time in cache for pages that have not been visited by the eviction server" : <number>,
"Clean pages currently in cache" : <number>,
"Current eviction generation" : <number>,
"Dirty pages currently in cache" : <number>,
"Entries in the root page" : <number>,
"Internal pages currently in cache" : <number>,
"Leaf pages currently in cache" : <number>,
"Maximum difference between current eviction generation when the page was last considered" : <number>,
"Maximum page size seen" : <number>,
"Minimum on-disk page image size seen" : <number>,
"Number of pages never visited by eviction server" : <number>,
"On-disk page image sizes smaller than a single allocation unit" : <number>,
"Pages created in memory and never written" : <number>,
"Pages currently queued for eviction" : <number>,
"Pages that could not be queued for eviction" : <number>,
"Refs skipped during cache traversal" : <number>,
"Size of the root page" : <number>,
"Total number of pages currently in cache" : <number>
},
"compression" : {
"compressed page maximum internal page size prior to compression" : <number>,
"compressed page maximum leaf page size prior to compression " : <number>,
"compressed pages read" : <number>,
"compressed pages written" : <number>,
"page written failed to compress" : <number>,
"page written was too small to compress" : 1
},
"cursor" : {
"bulk loaded cursor insert calls" : <number>,
"cache cursors reuse count" : <number>,
"close calls that result in cache" : <number>,
"create calls" : <number>,
"insert calls" : <number>,
"insert key and value bytes" : <number>,
"modify" : <number>,
"modify key and value bytes affected" : <number>,
"modify value bytes modified" : <number>,
"next calls" : <number>,
"open cursor count" : <number>,
"operation restarted" : <number>,
"prev calls" : <number>,
"remove calls" : <number>,
"remove key bytes removed" : <number>,
"reserve calls" : <number>,
"reset calls" : <number>,
"search calls" : <number>,
"search near calls" : <number>,
"truncate calls" : <number>,
"update calls" : <number>,
"update key and value bytes" : <number>,
"update value size change" : <num>
},
"reconciliation" : {
"dictionary matches" : <number>,
"fast-path pages deleted" : <number>,
"internal page key bytes discarded using suffix compression" : <number>,
"internal page multi-block writes" : <number>,
"internal-page overflow keys" : <number>,
"leaf page key bytes discarded using prefix compression" : <number>,
"leaf page multi-block writes" : <number>,
"leaf-page overflow keys" : <number>,
"maximum blocks required for a page" : <number>,
"overflow values written" : <number>,
"page checksum matches" : <number>,
"page reconciliation calls" : <number>,
"page reconciliation calls for eviction" : <number>,
"pages deleted" : <number>
},
"session" : {
"object compaction" : <number>,
},
"transaction" : {
"update conflicts" : <number>
}
},
"nindexes" : <number>,
"indexDetails" : {
"_id_" : {
"metadata" : {
"formatVersion" : <number>
},
...
},
...
},
"indexBuilds" : [
<string>,
],
"totalIndexSize" : <number>,
"totalSize" : <number>, // Available starting in MongoDB 4.4
"indexSizes" : {
"_id_" : <number>,
"<indexName>" : <number>,
...
},
"scaleFactor" : <number>
"ok" : <number>
}
Output输出
collStats.ns
-
The namespace of the current collection, which follows the format当前集合的命名空间,其格式为[database].[collection]
.[database].[collection]
。
collStats.size
-
The total uncompressed size in memory of all records in a collection. The集合中所有记录在内存中的未压缩总大小。size
does not include the size of any indexes associated with the collection, which thetotalIndexSize
field reports.size
不包括totalIndexSize
字段报告的与集合关联的任何索引的大小。Thescale
argument affects this value. Data compression does not affect this value.scale
参数会影响此值。数据压缩不会影响此值。
collStats.timeseries
-
timeseries
appears when you run the在时间序列集合上运行collStats
command on a time series collection.collStats
命令时显示。This document contains data for internal diagnostic use.本文档包含用于内部诊断的数据。
collStats.avgObjSize
-
The average size of an object in the collection.集合中对象的平均大小。Thescale
argument does not affect this value.scale
参数不影响此值。
collStats.numOrphanDocs
-
The number of orphaned documents in the collection.集合中孤立文档的数量。New in version 6.0.6.0版新增。
collStats.storageSize
-
The total amount of storage allocated to this collection for document storage.分配给此集合用于文档存储的存储总量。Thescale
argument affects this value.scale
参数会影响此值。If collection data is compressed (which is the如果采集数据被压缩(这是default for WiredTiger
), the storage size reflects the compressed size and may be smaller than the value forcollStats.size
.WiredTiger
的默认值),则存储大小会反映压缩后的大小,并且可能小于collStats.size
的值。storageSize
does not include index size. See不包括索引大小。请参阅totalIndexSize
for index sizing.totalIndexSize
了解索引大小。
collStats.freeStorageSize
-
Unavailable for the In-Memory Storage Engine内存存储引擎不可用The amount of storage available for reuse.可重复使用的存储量。Thescale
argument affects this value.scale
参数会影响此值。The field is only available if storage is available for reuse (i.e. greater than zero).只有当存储可重复使用(即大于零)时,该字段才可用。New in version 4.4.4.4版新增。
collStats.nindexes
-
The number of indexes on the collection. All collections have at least one index on the _id field.集合上的索引数。所有集合在_id
字段上至少有一个索引。nindexes
includes indexes currently being built in its count.在其计数中包括当前正在生成的索引。
collStats.indexDetails
-
A document that reports data from the WiredTiger storage engine for each index in the collection. Other storage engines will return an empty document.为集合中的每个索引报告WiredTiger存储引擎数据的文档。其他存储引擎将返回一个空文档。The fields in this document are the names of the indexes, while the values themselves are documents that contain statistics for the index provided by the storage engine. These statistics are for internal diagnostic use.此文档中的字段是索引的名称,而值本身是包含存储引擎提供的索引统计信息的文档。这些统计数据用于内部诊断。indexDetails
includes details on indexes currently being built.包括当前正在生成的索引的详细信息。
collStats.indexBuilds
-
An array that contains the names of the indexes that are currently being built on the collection.一个数组,包含当前正在集合上生成的索引的名称。Once an index build completes, the index does not appear in the一旦索引生成完成,该索引就不会出现在indexBuilds
.indexBuilds
中。
collStats.totalIndexSize
-
Sum of the disk space used by all indexes. The所有索引使用的磁盘空间的总和。scale
argument affects this value.scale
参数会影响此值。If an index uses prefix compression (which is the如果索引使用前缀压缩(这是default for WiredTiger
), the returned size reflects the compressed size for any such indexes when calculating the total.WiredTiger
的默认值),则在计算总数时,返回的大小反映任何此类索引的压缩大小。totalIndexSize
includes indexes currently being built in the total size.在总大小中包括当前正在生成的索引。
collStats.totalSize
-
The sum of thestorageSize
andtotalIndexSize
. Thescale
argument affects this value.storageSize
和totalIndexSize
的总和。scale
参数会影响此值。New in version 4.4.4.4版新增。
collStats.indexSizes
-
This field specifies the key and size of every existing index on the collection.此字段指定集合上每个现有索引的键和大小。Thescale
argument affects this value.scale
参数会影响此值。If an index uses prefix compression (which is the如果索引使用前缀压缩(这是default for WiredTiger
), the returned size reflects the compressed size.WiredTiger
的默认值),则返回的大小反映压缩后的大小。indexSizes
includes the sizes of indexes currently being built.包括当前正在生成的索引的大小。
collStats.scaleFactor
-
The命令使用的scale
value used by the command.scale
值。If you had specified a non-integer scale factor, MongoDB uses the integer part of the specified factor.如果您指定了一个非整数比例因子,MongoDB将使用指定因子的整数部分。For example, if you specify a scale factor of例如,如果指定的比例因子为1023.999
, MongoDB uses1023
as the scale factor.1023.999
,MongoDB将使用1023
作为比例因子。
collStats.max
-
Shows the maximum number of documents that may be present in a capped collection.显示封顶集合中可能存在的最大文档数。
collStats.maxSize
-
Shows the maximum size of a capped collection.显示封顶集合的最大大小。
collStats.wiredTiger
-
wiredTiger
only appears when using the WiredTiger storage engine.仅在使用WiredTiger存储引擎时显示。When using Queryable Encryption, WiredTiger data is redacted to only the使用可查询加密时,WiredTiger数据将被编辑为仅url
field.url
字段。This document contains data reported directly by the WiredTiger engine and other data for internal diagnostic use.本文档包含WiredTiger引擎直接报告的数据以及用于内部诊断的其他数据。
collStats.inMemory
-
inMemory
only appears when using the in-memory storage engine.仅在使用内存中存储引擎时显示。This document contains data reported directly by the storage engine and other data for internal diagnostic use.本文档包含存储引擎直接报告的数据以及供内部诊断使用的其他数据。