dbStats
Definition
dbStats
- The
dbStats
command returns storage statistics for agiven database. The command has the following syntax:
- db.runCommand( {
- dbStats: 1,
- scale: <number> //Optional
- } )
The dbStats
command takes the following fields:
ParameterDescriptiondbStats
1scaleOptional. 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 scale
value 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 1023
as the scale factor.
Starting in version 4.2, the output includes the scaleFactor
used 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 mongod
to restore the correct statistics after an unclean shutdown.
Output
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 the
dataSize
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 dataSize
decreases 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 thandataSize
for databasesusing the WiredTiger storage engine withcompression enabled.
dbStats.
indexes
- Contains a count of the total number of indexes across allcollections in the database.
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.
New in version 3.6.
Total size of all disk space in use on the filesystem where MongoDBstores data.
See also
New in version 3.6.
Total size of all disk capacity on the filesystem where MongoDBstores data.