- Reference >
- mongo Shell Methods >
- Collection Methods >
- db.collection.stats()
db.collection.stats()¶
Definition¶
- db.collection.stats(scale)¶
- db.collection.stats(options)¶
Returns statistics about the collection. The method includes the following parameters:
Parameter Type Description scale number 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 scale value of 1024.
Changed in version 3.0: Legacy parameter format. Mutually exclusive with options as a document.
options document Optional. Alternate option format. Mutually exclusive with scale as a scalar parameter. The use of this format optionally allows suppression or filtering of index details.
New in version 3.0.
The options document can contain the following fields and values:
Field Type Description scale number 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 scale value of 1024.
New in version 3.0.
indexDetails boolean Optional. If true, db.collection.stats() returns index details in addition to the collection stats.
Defaults to false.
New in version 3.0.
indexDetailsField document Optional. If indexDetails is true, use indexDetailsField to filter index details by specifying the index key. Use getIndexes() to discover index keys. You cannot use indexDetailsField with indexDetailsName.
New in version 3.0.
indexDetailsName string Optional. If indexDetails is true, use indexDetailsName to filter index details by specifying the index name. Use getIndexes() to discover index names. You cannot use indexDetailsName with indexDetailsField.
New in version 3.0.
Returns: A document that contains statistics on the specified collection. The stats() method provides a wrapper around the database command collStats.
Examples¶
The following operation returns stats on the people collection:
db.people.stats()
The following operation returns stats on the orders collection, suppressing all index stats except for those of the ascending index on the order_date field, and expressing sizes in kilobytes:
db.orders.stats( { scale: 1024,
indexDetails: true,
indexKey: { order_date: 1 } } )
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.