collStats
Definition
collStats
- The
collStats
command returns a variety of storage statisticsfor a given collection.
To run collStats
, use the db.runCommand( { <command> } )
method.
The collStats
command has the following syntax:
- {
- collStats: <string>,
- scale: <int>
- }
The command takes the following fields:
FieldTypeDescriptioncollStats
stringThe name of the target collection.
If the collection does not exist, collStats
returnsan error message.scale
intOptional. The scale factor for the various size data (with the exception ofthose sizes that specify the unit of measurement in the field name). Thevalue defaults to 1 to return size data in bytes. To displaykilobytes rather than bytes, specify a scale
value of 1024
.
If you specify a non-integer scale factor, MongoDB uses the integerpart of the specified factor. For example, if you specify a scalefactor of 1023.999
, MongoDB uses 1023
as the scale factor.
The scale factor rounds the affected size values to whole numbers.
Starting in version 4.2, the output includes the scaleFactor
used to scale the size values.
Note
Starting in version 4.2, MongoDB removes the MMAPv1 storageengine. In conjunction with this change, MongoDB removes theMMAPv1 specific collStats
option verbose
.
Behavior
Scaled Sizes
Unless otherwise specified by the metric name (such as "bytescurrently in the cache"
), values related to size are displayed inbytes 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 mongod
using the Wired Tiger storage engine, size statistics reported bycollStats
may be inaccurate.
The amount of drift depends on the number of insert, update, or deleteoperations performed between the last checkpoint and the unclean shutdown. Checkpointsusually occur every 60 seconds. However, mongod
instances runningwith non-default —syncdelay
settings may have more or less frequentcheckpoints.
Run validate
on each collection on the mongod
to restore the correct statistics after an unclean shutdown.
In-Progress Indexes
Starting in MongoDB 4.2, the collStats
includesinformation on indexes currently being built. For details, see:
collStats.nindexes
collStats.indexDetails
collStats.indexBuilds
collStats.totalIndexSize
collStats.indexSizes
Example
The following operation runs the collStats
command on therestaurants
collection, specifying a scale of 1024
bytes:
- db.runCommand( { collStats : "restaurants", scale: 1024 } )
The following document provides a representation of thecollStats
output. Depending on the configuration of yourcollection and the storage engine, the output fields may vary.
- {
- "ns" : <string>,
- "size" : <number>,
- "count" : <number>,
- "avgObjSize" : <number>,
- "storageSize" : <number>,
- "capped" : <boolean>,
- "max" : <number>,
- "maxSize" : <number>,
- "wiredTiger" : {
- "metadata" : {
- "formatVersion" : <num>
- },
- "creationString" : <string>
- "type" : <string>,
- "uri" : <string>,
- "LSM" : {
- "bloom filters in the LSM tree" : <number>,
- "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>,
- "total size of bloom filters" : <number>,
- "sleep for LSM checkpoint throttle" : <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 merge throttle" : <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 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 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>,
- "close calls that result in cache" : <number>,
- "create calls" : <number>,
- "cursor operation restarted" : <number>,
- "cursor-insert key and value bytes inserted" : <number>,
- "cursor-remove key bytes removed" : <number>,
- "cursor-update value bytes updated" : <number>,
- "cursors reused from cache" : <number>,
- "insert calls" : <number>,
- "modify calls" : <number>,
- "next calls" : <number>,
- "open cursor count" : <number>,
- "prev calls" : <number>,
- "remove calls" : <number>,
- "reserve calls" : <number>,
- "reset calls" : <number>,
- "search calls" : <number>,
- "search near calls" : <number>,
- "truncate calls" : <number>,
- "update calls" : <number>
- },
- "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" : 8,
- "infoObj" : "{ \"v\" : 2, \"key\" : { \"_id\" : 1 }, \"name\" : \"_id_\", \"ns\" : \"test.restaurants\" }"
- },
- ...
- },
- ...
- },
- "indexBuilds" : [ // Available starting in MongoDB 4.2
- <string>,
- ],
- "totalIndexSize" : <number>,
- "indexSizes" : {
- "_id_" : <number>,
- "<indexName>" : <number>,
- ...
- },
- // ...
- "scaleFactor" : <number> // Available starting in MongoDB 4.2
- "ok" : <number>
- }
Output
collStats.
ns
- The namespace of the current collection, which follows the format
[database].[collection]
.
collStats.
size
- The total uncompressed size in memory of all records in acollection. The
size
does notinclude the size of any indexes associated with the collection,which thetotalIndexSize
field reports.
The scale
argument affects this value. Data compression does notaffect this value.
collStats.
avgObjSize
- The average size of an object in the collection. The
scale
argument does not affect this value.
collStats.
storageSize
- The total amount of storage allocated to this collection fordocument storage. The
scale
argument affects thisvalue.
If collection data is compressed (which is the default forWiredTiger
), thestorage size reflects the compressed size and may be smaller thanthe value for collStats.size
.
storageSize
does not include index size. SeetotalIndexSize
for index sizing.
collStats.
nindexes
- The number of indexes on the collection. All collections have atleast one index on the _id field.
Starting in MongoDB 4.2, nindexes
includes in itscount those indexes currently being built.
New in version 3.0.0.
A document that reports data from the WiredTigerstorage engine for each index in the collection. Other storage engines willreturn an empty document.
The fields in this document are the names of the indexes, while thevalues themselves are documents that contain statistics for theindex provided by the storage engine. These statistics are forinternal diagnostic use.
Starting in MongoDB 4.2, indexDetails
includesdetails on indexes currently being built.
collStats.
indexBuilds
- An array that contains the names of the indexes that are currentlybeing built on the collection. Once an index build completes, theindex does not appear in the
indexBuilds
.
New in version 4.2.
If an index uses prefix compression (which is the defaultfor WiredTiger
), thereturned size reflects the compressed size for any such indexes whencalculating the total.
Starting in MongoDB 4.2, totalIndexSize
includesin its total the size of those indexes currently being built.
collStats.
indexSizes
- This field specifies the key and size of every existing index onthe collection. The
scale
argument affects this value.
If an index uses prefix compression (which is the defaultfor WiredTiger
), thereturned size reflects the compressed size.
Starting in MongoDB 4.2, indexSizes
includessizes of indexes currently being built.
If you had specified a non-integer scale factor, MongoDB uses theinteger part of the specified factor. For example, if you specify ascale factor of 1023.999
, MongoDB uses 1023
as the scalefactor.
New in version 4.2.
collStats.
capped
- This field will be “true” if the collection iscapped.
collStats.
max
- Shows the maximum number of documents that may be present in acapped collection.
collStats.
maxSize
- Shows the maximum size of a capped collection.
New in version 3.0.0.
wiredTiger
only appears when using theWiredTiger storage engine.
This document contains data reporteddirectly by the WiredTiger engine and other data for internaldiagnostic use.