collStats

Definition

collStats

The collStats command returns a variety of storage statistics for a given collection.

To run collStats, use the db.runCommand( { <command> } ) method.

The collStats command has the following syntax:

{
   collStats: <string>,
   scale: <int>,
   verbose: <boolean>
}

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 of 1024.

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:

db.runCommand( { collStats : "restaurant", scale: 1024 } )

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.

{
  "ns" : <string>,
  "count" : <number>,
  "size" : <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" : {
        "file allocation unit size" : <number>,
        "blocks allocated" : <number>,
        "checkpoint size" : <number>,
        "allocations requiring file extension" : <number>,
        "blocks freed" : <number>,
        "file magic number" : <number>,
        "file major version number" : <number>,
        "minor version number" : <number>,
        "file bytes available for reuse" : <number>,
        "file size in bytes" : <number>
     },
     "btree" : {
        "btree checkpoint generation" : <number>,
        "column-store variable-size deleted values" : <number>,
        "column-store fixed-size leaf pages" : <number>,
        "column-store internal pages" : <number>,
        "column-store variable-size leaf pages" : <number>,
        "pages rewritten by compaction" : <number>,
        "number of key/value pairs" : <number>,
        "fixed-record size" : <number>,
        "maximum tree depth" : <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>,
        "overflow pages" : <number>,
        "row-store internal pages" : <number>,
        "row-store leaf pages" : <number>
     },
     "cache" : {
        "bytes read into cache" : <number>,
        "bytes written from cache" : <number>,
        "checkpoint blocked page eviction" : <number>,
        "unmodified pages evicted" : <number>,
        "page split during eviction deepened the tree" : <number>,
        "modified pages evicted" : <number>,
        "data source pages selected for eviction unable to be evicted" : <number>,
        "hazard pointer blocked page eviction" : <number>,
        "internal pages evicted" : <number>,
        "pages split during eviction" : <number>,
        "in-memory page splits" : <number>,
        "overflow values cached in memory" : <number>,
        "pages read into cache" : <number>,
        "overflow pages read into cache" : <number>,
        "pages written from cache" : 2
     },
     "compression" : {
        "raw compression call failed, no additional data available" : <number>,
        "raw compression call failed, additional data available" : <number>,
        "raw compression call succeeded" : <number>,
        "compressed pages read" : <number>,
        "compressed pages written" : <number>,
        "page written failed to compress" : <number>,
        "page written was too small to compress" : 1
     },
     "cursor" : {
        "create calls" : <number>,
        "insert calls" : <number>,
        "bulk-loaded cursor-insert calls" : <number>,
        "cursor-insert key and value bytes inserted" : <number>,
        "next calls" : <number>,
        "prev calls" : <number>,
        "remove calls" : <number>,
        "cursor-remove key bytes removed" : <number>,
        "reset calls" : <number>,
        "search calls" : <number>,
        "search near calls" : <number>,
        "update calls" : <number>,
        "cursor-update value bytes updated" : <number>
     },
     "reconciliation" : {
        "dictionary matches" : <number>,
        "internal page multi-block writes" : <number>,
        "leaf page multi-block writes" : <number>,
        "maximum blocks required for a page" : <number>,
        "internal-page overflow keys" : <number>,
        "leaf-page overflow keys" : <number>,
        "overflow values written" : <number>,
        "pages deleted" : <number>,
        "page checksum matches" : <number>,
        "page reconciliation calls" : <number>,
        "page reconciliation calls for eviction" : <number>,
        "leaf page key bytes discarded using prefix compression" : <number>,
        "internal page key bytes discarded using suffix compression" : <number>
     },
     "session" : {
        "object compaction" : <number>,
        "open cursor count" : <number>
     },
     "transaction" : {
        "update conflicts" : <number>
     }
  },
  "nindexes" : <number>,
  "totalIndexSize" : <number>,
  "indexSizes" : {
          "_id_" : <number>,
          "username" : <number>
  },
  // ...
  "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 a collection. The size does not include the size of any indexes associated with the collection, which the totalIndexSize field re