db.stats()

Description

db.stats(scale)

Returns statistics that reflect the use state of a single database.

The db.stats() method has the following parameter:

Parameter Type Description
scale number Optional. The scale at which to deliver results. Unless specified, this command returns all data in bytes.
Returns:A document with statistics reflecting the database system’s state. For an explanation of the output, see dbStats.

The db.stats() method is a wrapper around the dbStats database command.

Behavior

Accuracy after Unexpected Shutdown

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

Example

The following example converts the returned values to kilobytes:

db.stats(1024)

Note

The scale factor rounds values to whole numbers.