db.stats()
Description
db.
stats
(scale)- Returns statistics that reflect the use state of a single database.
The db.stats()
method is a wrapper around thedbStats
database command.
Parameters
The db.stats()
method has the following optional parameter:
Parameter | Type | Description |
---|---|---|
scale | number | Optional. 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. |
Output
The db.stats()
method returns a document with statistics reflectingthe database system’s state. For an explanation of theoutput, see Output.
Behavior
Accuracy after Unexpected Shutdown
After an unclean shutdown of a mongod
using the Wired Tiger storage engine, count and size statistics reported bydb.stats
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.
Example
The following example returns various size values in kilobytes:
- db.stats(1024)
Note
The scale factor rounds values to whole numbers.