- Reference >
- Database Commands >
- Diagnostic Commands >
- collStats
collStats¶
On this page
Definition¶
-
collStats¶ The
collStatscommand returns a variety of storage statistics for a given collection.To run
collStats, use thedb.runCommand( { <command> } )method.The
collStatscommand has the following syntax:The command takes the following fields:
Field Type Description collStatsstring The name of the target collection.
If the collection does not exist,
collStatsreturns an error message.scaleint Optional. The scale used in the output to display the sizes of items. By default, output displays sizes in bytes. To display kilobytes rather than bytes, specify a
scalevalue of1024.The scale factor rounds values to whole numbers.
verboseboolean Optional. When
true,collStatsincreases reporting for the MMAPv1 Storage Engine.Defaults to false.
Behavior¶
Accuracy after Unexpected Shutdown¶
After an unclean shutdown of a mongod using the Wired Tiger storage engine, size statistics reported by
collStats may be inaccurate.
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. However, mongod instances running
with non-default --syncdelay settings may have more or less frequent
checkpoints.
Run validate on each collection on the mongod
to restore the correct statistics after an unclean shutdown.
Example¶
The following operation runs the collStats command on the
restaurant collection, specifying a scale of 1024 bytes:
The following document provides a representation of the
collStats output. Depending on the configuration of your
collection and the storage engine, the output fields may include a
subset of the fields.
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 a collection. The
sizedoes not include the size of any indexes associated with the collection, which thetotalIndexSizefield reports.For the deprecated MMAPv1 storage engine,
sizeincludes the record’s padding but not the record header, which is 16 bytes per record.The
scaleargument affectssize. Data compression does not affect this value.
-
collStats.count¶ The number of objects or documents in this collection.
-
collStats.avgObjSize¶ The average size of an object in the collection (plus any padding for MMAPv1). The
scaleargument does not affect this value.
-
collStats.storageSize¶ The total amount of storage allocated to this collection for document storage. The
scaleargument affects this value.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.storageSizedoes not include index size. SeetotalIndexSizefor index sizing.For MMAPv1,
storageSizewill not decrease as you remove or shrink documents.
-
collStats.numExtents¶ The total number of contiguously allocated data file regions. Only present when using the MMAPv1 storage engine.
-
collStats.nindexes¶ The number of indexes on the collection. All collections have at least one index on the _id field.
-
collStats.lastExtentSize¶ The size of the last extent allocated. The
scaleargument affects this value. Only present when using themmapv1storage engine.
-
collStats.paddingFactor¶ Deprecated since version 3.0.0:
paddingFactoris no longer used in 3.0.0, and remains hard coded to 1.0 for compatibility only.paddingFactoronly appears when using themmapv1storage engine.
-
collStats.userFlags¶ A number that indicates the user-set flags on the collection.
userFlagsonly appears when using themmapv1storage engine.Changed in version 3.0.0:
userFlagsreports on theusePowerOf2Sizesand thenoPaddingflags.0corresponds tousePowerOf2Sizesflag set tofalseandnoPaddingflag set tofalse.1corresponds tousePowerOf2Sizesflag set totrueandnoPaddingflag set tofalse.2corresponds tousePowerOf2Sizesflag set tofalseandnoPaddingflag set totrue.3corresponds tousePowerOf2Sizesflag set totrueandnoPaddingflag set totrue.
Note
MongoDB 3.0 ignores the
usePowerOf2Sizesflag. SeecollModanddb.createCollection()for more information.
-
collStats.totalIndexSize¶ The total size of all indexes. The
scaleargument affects this value.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.
-
collStats.indexSizes¶ This field specifies the key and size of every existing index on the collection. The
scaleargument affects this value.If an index uses prefix compression (which is the
default for WiredTiger), the returned size reflects the compressed size.
-
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¶ New in version 3.0.0.
wiredTigeronly appears when using the WiredTiger storage engine.This document contains data reported directly by the WiredTiger engine and other data for internal diagnostic use.
-
collStats.indexDetails¶ New in version 3.0.0.
A document that reports data from the WiredTiger storage engine for each index in the collection. Other storage engines will return an empty document.
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.