- Reference >
- Database Commands >
- Diagnostic Commands >
- collStats
collStats¶
On this page
Definition¶
-
collStats
¶ The
collStats
command returns a variety of storage statistics for a given collection.To run
collStats
, use thedb.runCommand( { <command> } )
method.The
collStats
command has the following syntax:The command takes the following fields:
Field Type Description collStats
string The name of the target collection.
If the collection does not exist,
collStats
returns an error message.scale
int 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
scale
value of1024
.The scale factor rounds values to whole numbers.
verbose
boolean Optional. When
true
,collStats
increases 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.
count
¶ The number of objects or documents in this collection.
-
collStats.
size
¶ The total size in memory of all records in a collection. This value does not include the record header, which is 16 bytes per record, but does include the record’s padding. Additionally
size
does not include the size of any indexes associated with the collection, which thetotalIndexSize
field reports.The
scale
argument affects this value.
-
collStats.
avgObjSize
¶ The average size of an object in the collection (plus any padding). The
scale
argument does not affect this value.
-
collStats.
storageSize
¶ The total amount of storage allocated to this collection for document storage. The
scale
argument affects this value.storageSize
does not include index size. SeetotalIndexSize
for index sizing.For MMAPv1,
storageSize
will 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
scale
argument affects this value. Only present when using themmapv1
storage engine.
-
collStats.
paddingFactor
¶ Deprecated since version 3.0.0:
paddingFactor
is no longer used in 3.0.0, and remains hard coded to 1.0 for compatibility only.paddingFactor
only appears when using themmapv1
storage engine.
-
collStats.
userFlags
¶ A number that indicates the user-set flags on the collection.
userFlags
only appears when using themmapv1
storage engine.Changed in version 3.0.0:
userFlags
reports on theusePowerOf2Sizes
and thenoPadding
flags.0
corresponds tousePowerOf2Sizes
flag set tofalse
andnoPadding
flag set tofalse
.1
corresponds tousePowerOf2Sizes
flag set totrue
andnoPadding
flag set tofalse
.2
corresponds tousePowerOf2Sizes
flag set tofalse
andnoPadding
flag set totrue
.3
corresponds tousePowerOf2Sizes
flag set totrue
andnoPadding
flag set totrue
.
Note
MongoDB 3.0 ignores the
usePowerOf2Sizes
flag. SeecollMod
anddb.createCollection()
for more information.
-
collStats.
totalIndexSize
¶ The total size of all indexes. The
scale
argument affects this value.
-
collStats.
indexSizes
¶ This field specifies the key and size of every existing index on the collection. The
scale
argument affects this value.
-
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.
wiredTiger
only 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.