Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
193 lines (138 sloc) 5.98 KB
.. default-domain:: mongodb
.. contents:: On this page
:backlinks: none
:depth: 1
:class: singlecol
.. dbcommand:: collStats
The :dbcommand:`collStats` command returns a variety of storage statistics
for a given collection. Use the following syntax:
.. code-block:: javascript
{ 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
:method:`db.collection.stats()` helper in the :program:`mongo` shell.
.. code-block:: javascript
> 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.
.. data:: collStats.ns
The namespace of the current collection, which follows the format
.. data:: collStats.count
The number of objects or documents in this collection.
.. data:: 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 :term:`padding`. Additionally
:data:`~collStats.size` does not include the size of any indexes
associated with the collection, which the
:data:`~collStats.totalIndexSize` field reports.
The ``scale`` argument affects this value.
.. data:: collStats.avgObjSize
The average size of an object in the collection. The ``scale``
argument affects this value.
.. data:: collStats.storageSize
The total amount of storage allocated to this collection for
:term:`document` storage. The ``scale`` argument affects this
value. The :data:`~collStats.storageSize` does not decrease as you remove or
shrink documents.
.. sum of all extents (no indexes or the $freelist)
.. include links to eventual documentation of storage management
.. data:: collStats.numExtents
The total number of contiguously allocated data file regions.
.. data:: collStats.nindexes
The number of indexes on the collection. All collections have at
least one index on the :term:`_id` field.
.. versionchanged:: 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 :program:`mongod` may not have an
``_id`` index.
.. data:: collStats.lastExtentSize
The size of the last extent allocated. The ``scale`` argument
affects this value.
.. data:: 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. :program:`mongod` automatically calculates this
padding factor
.. data:: collStats.flags
.. versionchanged:: 2.2
Removed in version 2.2 and replaced with the :data:`~collStats.userFlags`
and :data:`~collStats.systemFlags` fields.
Indicates the number of flags on the current collection. In version
2.0, the only flag notes the existence of an :term:`index` on the
:term:`_id` field.
.. data:: collStats.systemFlags
.. versionadded:: 2.2
Reports the flags on this collection that reflect internal server
options. Typically this value is ``1`` and reflects the existence
of an :term:`index` on the ``_id`` field.
.. data:: collStats.userFlags
.. versionadded:: 2.2
Reports the flags on this collection set by the user. In version
2.2 the only user flag is :collflag:`usePowerOf2Sizes`.
If :collflag:`usePowerOf2Sizes` is enabled, :data:`~collStats.userFlags` will
be set to ``1``, otherwise :data:`~collStats.userFlags` will be ``0``.
See the :dbcommand:`collMod` command for more information on setting user
flags and :collflag:`usePowerOf2Sizes`.
.. data:: collStats.totalIndexSize
The total size of all indexes. The ``scale`` argument affects this
.. data:: collStats.indexSizes
This field specifies the key and size of every existing index on
the collection. The ``scale`` argument affects this value.
The following is an example of :method:`db.collection.stats()` and
:dbcommand:`collStats` output:
.. code-block:: javascript
"ns" : "<database>.<collection>",
"count" : <number>,
"size" : <number>,
"avgObjSize" : <number>,
"storageSize" : <number>,
"numExtents" : <number>,
"nindexes" : <number>,
"lastExtentSize" : <number>,
"paddingFactor" : <number>,
"systemFlags" : <bit>,
"userFlags" : <bit>,
"totalIndexSize" : <number>,
"indexSizes" : {
"_id_" : <number>,
"a_1" : <number>
"ok" : 1
Jump to Line
Something went wrong with that request. Please try again.