dbStats

Definition

  • dbStats
  • The dbStats command returns storage statistics for agiven database. The command has the following syntax:
  1. db.runCommand( {
  2. dbStats: 1,
  3. scale: <number> //Optional
  4. } )

The dbStats command takes the following fields:

ParameterDescriptiondbStats1scaleOptional. The scale factor for the various size data. Thescale defaults to 1 to return size data in bytes. Todisplay kilobytes rather than bytes, specify a scalevalue of 1024.

If you specify a non-integer scale factor, MongoDB uses theinteger part of the specified factor. For example, if youspecify a scale factor of 1023.999, MongoDB uses 1023as the scale factor.

Starting in version 4.2, the output includes the scaleFactorused to scale the size values.

In the mongo shell, the db.stats() functionprovides a wrapper around dbStats.

Behavior

The time required to run the command depends on the total size of thedatabase. Because the command must touch all data files, the commandmay take several seconds to run.

Accuracy after Unexpected Shutdown

After an unclean shutdown of a mongod using the Wired Tiger storage engine, count and size statistics reported bydbStats 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 mongodto restore the correct statistics after an unclean shutdown.

Output

  • dbStats.db
  • Contains the name of the database.
  • dbStats.collections
  • Contains a count of the number of collections in that database.
  • dbStats.objects
  • Contains a count of the number of objects (i.e. documents) inthe database across all collections.
  • dbStats.avgObjSize
  • The average size of each document in bytes. This is thedataSize divided by the number of documents. Thescale argument does not affect theavgObjSize value.
  • dbStats.dataSize
  • The total size of the uncompressed data held in this database.The dataSize decreaseswhen you remove documents.

For databases using the WiredTiger storage engine,dataSize may be larger than storageSize if compression is enabled. The dataSizedecreases when documents shrink.

  • dbStats.storageSize
  • The total amount of space allocated to collections in this databasefor document storage. The storageSize doesnot decrease as you remove orshrink documents. This value may be smaller than dataSize for databasesusing the WiredTiger storage engine withcompression enabled.
  • dbStats.numExtents
  • Contains a count of the number of extents in the database acrossall collections.
  • dbStats.indexes
  • Contains a count of the total number of indexes across allcollections in the database.
  • dbStats.indexSize
  • The total size of all indexes created on this database.
  • dbStats.scaleFactor
  • The scale value used by the command.

If you 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.

  • dbStats.fsUsedSize

New in version 3.6.

Total size of all disk space in use on the filesystem where MongoDBstores data.

See also

—dbpath

  • dbStats.fsTotalSize

New in version 3.6.

Total size of all disk capacity on the filesystem where MongoDBstores data.