- Reference >
- Database Commands >
- Diagnostic Commands >
- collStats
collStats¶
On this page
Definition¶
-
collStats¶ The
collStatscommand returns a variety of storage statistics for a given collection.To run
collStats, use thedb.runCommand( { <command> } )method.The
collStatscommand has the following syntax:The command takes the following fields:
Field Type Description collStatsstring The name of the target collection.
If the collection does not exist,
collStatsreturns an error message.scaleint Optional. The scale used in the output to display the sizes of items. By default, output displays sizes in bytes. To display kilobytes rather than bytes, specify a
scalevalue of1024.The scale factor rounds values to whole numbers.
verboseboolean Optional. When
true,collStatsincreases reporting for the MMAPv1 Storage Engine.Defaults to false.
Example¶
The following operation runs the collStats command on the
restaurant collection, specifying a scale of 1024 bytes:
The following document provides a representation of the
collStats output. Depending on the configuration of your
collection and the storage engine, the output fields may include a
subset of the fields.
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
sizedoes not include the size of any indexes associated with the collection, which thetotalIndexSizefield reports.The
scaleargument affects this value.
-
collStats.avgObjSize¶ The average size of an object in the collection. The
scaleargument does not affect this value.
-
collStats.storageSize¶ The total amount of storage allocated to this collection for document storage. The
scaleargument affects this value.storageSizedoes not include index size. SeetotalIndexSizefor index sizing.For MMAPv1,
storageSizewill 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.
-
collStats.lastExtentSize¶ The size of the last extent allocated. The
scaleargument affects this value. Only present when using themmapv1storage engine.
-
collStats.paddingFactor¶ Deprecated since version 3.0.0:
paddingFactoris no longer used in 3.0.0, and remains hard coded to 1.0 for compatibility only.paddingFactoronly appears when using themmapv1storage engine.
-
collStats.userFlags¶ A number that indicates the user-set flags on the collection.
userFlagsonly appears when using themmapv1storage engine.Changed in version 3.0.0:
userFlagsreports on theusePowerOf2Sizesand thenoPaddingflags.0corresponds tousePowerOf2Sizesflag set tofalseandnoPaddingflag set tofalse.1corresponds tousePowerOf2Sizesflag set totrueandnoPaddingflag set tofalse.2corresponds tousePowerOf2Sizesflag set tofalseandnoPaddingflag set totrue.3corresponds tousePowerOf2Sizesflag set totrueandnoPaddingflag set totrue.
Note
MongoDB 3.0 ignores the
usePowerOf2Sizesflag. SeecollModanddb.createCollection()for more information.
-
collStats.totalIndexSize¶ The total size of all indexes. The
scaleargument affects this value.
-
collStats.indexSizes¶ This field specifies the key and size of every existing index on the collection. The
scaleargument 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.
wiredTigeronly 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 WiredTiger storage engine for each index in the collection. Other storage engines will return an empty document.
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.