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.
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 re