Navigation
This version of the manual is no longer supported.

Database Statistics Reference

On this page

Synopsis

MongoDB can report data that reflects the current state of the “active” database. In this context “database,” refers to a single MongoDB database. To run dbStats issue this command in the shell:

db.runCommand( { dbStats: 1 } )

The mongo shell provides the helper function db.stats(). Use the following form:

db.stats()

The above commands are equivalent. Without any arguments, db.stats() returns values in bytes. To convert the returned values to kilobytes, use the scale argument:

db.stats(1024)

Or:

db.runCommand( { dbStats: 1, scale: 1024 } )

Note

Because scaling rounds values to whole numbers, scaling may return unlikely or unexpected results.

The above commands are equivalent. See the dbStats database command and the db.stats() helper for the mongo shell for additional information.

Fields

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) in the database across all collections.

dbStats.avgObjSize

The average size of each document in bytes. This is the dataSize divided by the number of documents.

dbStats.dataSize

The total size of the data held in this database including the padding factor. The scale argument affects this value. The dataSize will not decrease when documents shrink, but will decrease when you remove documents.

dbStats.storageSize

The total amount of space allocated to collections in this database for document storage. The scale argument affects this value. The storageSize does not decrease as you remove or shrink documents.

dbStats.numExtents

Contains a count of the number of extents in the database across all collections.

dbStats.indexes

Contains a count of the total number of indexes across all collections in the database.

dbStats.indexSize

The total size of all indexes created on this database. The scale arguments affects this value.

dbStats.fileSize

The total size of the data files that hold the database. This value includes preallocated space and the padding factor. The value of fileSize only reflects the size of the data files for the database and not the namespace file.

The scale argument affects this value.

dbStats.nsSizeMB

The total size of the namespace files (i.e. that end with .ns) for this database. You cannot change the size of the namespace file after creating a database, but you can change the default size for all new namespace files with the nssize runtime option.

See also

The nssize option, and Maximum Namespace File Size