Navigation
This version of the documentation is archived and no longer supported.

collStats

On this page

Definition

collStats

The collStats command returns a variety of storage statistics for a given collection. Use the following syntax:

{ collStats: "collection" , scale : 1024 }

Specify the collection you want statistics for, and use the scale argument to scale the output. The above example will display values in kilobytes.

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
        "numExtents" : 1,               // number of extents (contiguously allocated chunks of datafile space)
        "nindexes" : 2,                 // number of indexes
        "lastExtentSize" : 3840,        // size of the most recently created extent in bytes
        "paddingFactor" : 1,            // padding can speed up updates if documents grow
        "flags" : 1,
        "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 unpredictable and 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 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. The storageSize does not decrease as you remove or shrink documents.

collStats.numExtents

The total number of contiguously allocated data file regions.

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.

collStats.paddingFactor

The amount of space added to the end of each document at insert time. The document padding provides a small amount of extra space on disk to allow a document to grow slightly without needing to move the document. mongod automatically calculates this padding factor

collStats.flags

Changed in version 2.2: Removed in version 2.2 and replaced with the userFlags and systemFlags fields.

Indicates the number of flags on the current collection. In version 2.0, the only flag notes the existence of an index on the _id field.

collStats.systemFlags

New in version 2.2.

Reports the flags on this collection that reflect internal server options. Typically this value is 1 and reflects the existence of an index on the _id field.

collStats.userFlags

New in version 2.2.

Reports the flags on this collection set by the user. In version 2.2 the only user flag is usePowerOf2Sizes. If usePowerOf2Sizes is enabled, userFlags will be set to 1, otherwise it will be 0.

See the collMod command for more information on setting user flags and usePowerOf2Sizes.

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.capped

This field will be “true” if the collection is capped.

collStats.max

Shows the maximum number of documents that may be present in a capped collection.

←   buildInfo connPoolStats  →