- Reference >
- Database Commands >
- Diagnostic Commands >
- collStats
collStats¶
Definition¶
- collStats¶
The collStats command returns a variety of storage statistics for a given collection. Use the following syntax:
{ collStats: "collection" , scale : 1024, verbose: true }
Specify the collection you want statistics for, and use the scale argument to scale the output: a value of 1024 renders the results in kilobytes. The verbose: true option increases reporting for the mmapv1 storage engine.
Examine the following example output, which uses the db.collection.stats() helper in the mongo shell.
> db.users.stats() { "ns" : "app.users", // namespace "count" : 9, // number of documents "size" : 432, // collection size in bytes "avgObjSize" : 48, // average object size in bytes "storageSize" : 3840, // (pre)allocated space for the collection in bytes "nindexes" : 2, // number of indexes "totalIndexSize" : 16384, // total index size in bytes "indexSizes" : { // size of specific indexes in bytes "_id_" : 8192, "username" : 8192 }, // ... "ok" : 1 }
Note
The scale factor rounds values to whole numbers. This can produce unexpected results in some situations.
If collStats operates on a capped collection, then the following fields will also be present:
> db.users.stats() { // ... "capped" : true, "max" : NumberLong("9223372036854775807"), "ok" : 1 }
Output¶
- collStats.ns¶
The namespace of the current collection, which follows the format [database].[collection].
- collStats.count¶
The number of objects or documents in this collection.
- collStats.size¶
The total size in memory of all records in a collection. This value does not include the record header, which is 16 bytes per record, but does include the record’s padding. Additionally size does not include the size of any indexes associated with the collection, which the totalIndexSize field reports.
The scale argument affects this value.
- collStats.avgObjSize¶
The average size of an object in the collection. The scale argument does not affect this value.
- collStats.storageSize¶
The total amount of storage allocated to this collection for document storage. The scale argument affects this value.
For mmapv1, storageSize will not decrease as you remove or shrink documents.
- collStats.numExtents¶
The total number of contiguously allocated data file regions. Only present when using the mmapv1 storage engine.
- collStats.nindexes¶
The number of indexes on the collection. All collections have at least one index on the _id field.
Changed in version 2.2: Before 2.2, capped collections did not necessarily have an index on the _id field, and some capped collections created with pre-2.2 versions of mongod may not have an _id index.
- collStats.lastExtentSize¶
The size of the last extent allocated. The scale argument affects this value. Only present when using the mmapv1 storage engine.
- collStats.paddingFactor¶
Deprecated since version 3.0.0: paddingFactor is no longer used in 3.0.0, and remains hard coded to 1.0 for compatibility only.
paddingFactor only appears when using the mmapv1 storage engine.
- collStats.userFlags¶
New in version 2.2.
A number that indicates the user-set flags on the collection. userFlags only appears when using the mmapv1 storage engine.
Changed in version 3.0.0: userFlags reports on the usePowerOf2Sizes and the noPadding flags.
- 0 corresponds to usePowerOf2Sizes flag set to false and noPadding flag set to false.
- 1 corresponds to usePowerOf2Sizes flag set to true and noPadding flag set to false.
- 2 corresponds to usePowerOf2Sizes flag set to false and noPadding flag set to true.
- 3 corresponds to usePowerOf2Sizes flag set to true and noPadding flag set to true.
Note
MongoDB 3.0 ignores the usePowerOf2Sizes flag. See collMod and db.createCollection() for more information.
- collStats.totalIndexSize¶
The total size of all indexes. The scale argument affects this value.
- collStats.indexSizes¶
This field specifies the key and size of every existing index on the collection. The scale argument affects this value.
- collStats.max¶
Shows the maximum number of documents that may be present in a capped collection.
- collStats.maxSize¶
Shows the maximum size of a capped collection.
- collStats.wiredTiger¶
New in version 3.0.0.
wiredTiger only appears when using the wiredTiger storage engine. This document contains data reported directly by the WiredTiger engine and other data for internal diagnostic use.
- collStats.indexDetails¶
New in version 3.0.0.
A document that reports data from the storage engine for each index in the collection.
The fields in this document are the names of the indexes, while the values themselves are documents that contain statistics for the index provided by the storage engine. These statistics are for internal diagnostic use.
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.