collStats

Definition

  • collStats
  • The collStats command returns a variety of storage statisticsfor a given collection.

To run collStats, use the db.runCommand( { <command> } ) method.

The collStats command has the following syntax:

  1. {
  2. collStats: <string>,
  3. scale: <int>
  4. }

The command takes the following fields:

FieldTypeDescriptioncollStatsstringThe name of the target collection.

If the collection does not exist, collStats returnsan error message.scaleintOptional. The scale factor for the various size data (with the exception ofthose sizes that specify the unit of measurement in the field name). Thevalue defaults to 1 to return size data in bytes. To displaykilobytes rather than bytes, specify a scale value of 1024.

If you specify a non-integer scale factor, MongoDB uses the integerpart of the specified factor. For example, if you specify a scalefactor of 1023.999, MongoDB uses 1023 as the scale factor.

The scale factor rounds the affected size values to whole numbers.

Starting in version 4.2, the output includes the scaleFactorused to scale the size values.

Note

Starting in version 4.2, MongoDB removes the MMAPv1 storageengine. In conjunction with this change, MongoDB removes theMMAPv1 specific collStats option verbose.

Behavior

Scaled Sizes

Unless otherwise specified by the metric name (such as "bytescurrently in the cache"), values related to size are displayed inbytes and can be overridden by scale.

The scale factor rounds the affected size values to whole numbers.

Accuracy after Unexpected Shutdown

After an unclean shutdown of a mongod using the Wired Tiger storage engine, size statistics reported bycollStats may be inaccurate.

The amount of drift depends on the number of insert, update, or deleteoperations performed between the last checkpoint and the unclean shutdown. Checkpointsusually occur every 60 seconds. However, mongod instances runningwith non-default —syncdelay settings may have more or less frequentcheckpoints.

Run validate on each collection on the mongodto restore the correct statistics after an unclean shutdown.

In-Progress Indexes

Starting in MongoDB 4.2, the collStats includesinformation on indexes currently being built. For details, see:

Example

The following operation runs the collStats command on therestaurants collection, specifying a scale of 1024 bytes:

  1. db.runCommand( { collStats : "restaurants", scale: 1024 } )

The following document provides a representation of thecollStats output. Depending on the configuration of yourcollection and the storage engine, the output fields may vary.

  1. {
  2. "ns" : <string>,
  3. "size" : <number>,
  4. "count" : <number>,
  5. "avgObjSize" : <number>,
  6. "storageSize" : <number>,
  7. "capped" : <boolean>,
  8. "max" : <number>,
  9. "maxSize" : <number>,
  10. "wiredTiger" : {
  11. "metadata" : {
  12. "formatVersion" : <num>
  13. },
  14. "creationString" : <string>
  15. "type" : <string>,
  16. "uri" : <string>,
  17. "LSM" : {
  18. "bloom filters in the LSM tree" : <number>,
  19. "bloom filter false positives" : <number>,
  20. "bloom filter hits" : <number>,
  21. "bloom filter misses" : <number>,
  22. "bloom filter pages evicted from cache" : <number>,
  23. "bloom filter pages read into cache" : <number>,
  24. "total size of bloom filters" : <number>,
  25. "sleep for LSM checkpoint throttle" : <number>,
  26. "chunks in the LSM tree" : <number>,
  27. "highest merge generation in the LSM tree" : <number>,
  28. "queries that could have benefited from a Bloom filter that did not exist" : <number>,
  29. "sleep for LSM merge throttle" : <number>
  30. },
  31. "block-manager" : {
  32. "allocations requiring file extension" : <number>,
  33. "blocks allocated" : <number>,
  34. "blocks freed" : <number>,
  35. "checkpoint size" : <number>,
  36. "file allocation unit size" : <number>,
  37. "file bytes available for reuse" : <number>,
  38. "file magic number" : <number>,
  39. "file major version number" : <number>,
  40. "file size in bytes" : <number>,
  41. "minor version number" : <number>
  42. },
  43. "btree" : {
  44. "btree checkpoint generation" : <number>,
  45. "column-store fixed-size leaf pages" : <number>,
  46. "column-store internal pages" : <number>,
  47. "column-store variable-size RLE encoded values" : <number>,
  48. "column-store variable-size deleted values" : <number>,
  49. "column-store variable-size leaf pages" : <number>,
  50. "fixed-record size" : <number>,
  51. "maximum internal page key size" : <number>,
  52. "maximum internal page size" : <number>,
  53. "maximum leaf page key size" : <number>,
  54. "maximum leaf page size" : <number>,
  55. "maximum leaf page value size" : <number>,
  56. "maximum tree depth" : <number>,
  57. "number of key/value pairs" : <number>,
  58. "overflow pages" : <number>,
  59. "pages rewritten by compaction" : <number>,
  60. "row-store internal pages" : <number>,
  61. "row-store leaf pages" : <number>
  62. },
  63. "cache" : {
  64. "bytes currently in the cache" : <number>,
  65. "bytes dirty in the cache cumulative" : <number>,
  66. "bytes read into cache" : <number>,
  67. "bytes written from cache" : <number>,
  68. "checkpoint blocked page eviction" : <number>,
  69. "data source pages selected for eviction unable to be evicted" : <number>,
  70. "eviction walk passes of a file" : <number>,
  71. "eviction walk target pages histogram - 0-9" : <number>,
  72. "eviction walk target pages histogram - 10-31" : <number>,
  73. "eviction walk target pages histogram - 128 and higher" : <number>,
  74. "eviction walk target pages histogram - 32-63" : <number>,
  75. "eviction walk target pages histogram - 64-128" : <number>,
  76. "eviction walks abandoned" : <number>,
  77. "eviction walks gave up because they restarted their walk twice" : <number>,
  78. "eviction walks gave up because they saw too many pages and found no candidates" : <number>,
  79. "eviction walks gave up because they saw too many pages and found too few candidates" : <number>,
  80. "eviction walks reached end of tree" : <number>,
  81. "eviction walks started from root of tree" : <number>,
  82. "eviction walks started from saved location in tree" : <number>,
  83. "hazard pointer blocked page eviction" : <number>,
  84. "in-memory page passed criteria to be split" : <number>,
  85. "in-memory page splits" : <number>,
  86. "internal pages evicted" : <number>,
  87. "internal pages split during eviction" : <number>,
  88. "leaf pages split during eviction" : <number>,
  89. "modified pages evicted" : <number>,
  90. "overflow pages read into cache" : <number>,
  91. "page split during eviction deepened the tree" : <number>,
  92. "page written requiring cache overflow records" : <number>,
  93. "pages read into cache" : <number>,
  94. "pages read into cache after truncate" : <number>,
  95. "pages read into cache after truncate in prepare state" : <number>,
  96. "pages read into cache requiring cache overflow entries" : <number>,
  97. "pages requested from the cache" : <number>,
  98. "pages seen by eviction walk" : <number>,
  99. "pages written from cache" : <number>,
  100. "pages written requiring in-memory restoration" : <number>,
  101. "tracked dirty bytes in the cache" : <number>,
  102. "unmodified pages evicted" : <number>
  103. },
  104. "cache_walk" : {
  105. "Average difference between current eviction generation when the page was last considered" : <number>,
  106. "Average on-disk page image size seen" : <number>,
  107. "Average time in cache for pages that have been visited by the eviction server" : <number>,
  108. "Average time in cache for pages that have not been visited by the eviction server" : <number>,
  109. "Clean pages currently in cache" : <number>,
  110. "Current eviction generation" : <number>,
  111. "Dirty pages currently in cache" : <number>,
  112. "Entries in the root page" : <number>,
  113. "Internal pages currently in cache" : <number>,
  114. "Leaf pages currently in cache" : <number>,
  115. "Maximum difference between current eviction generation when the page was last considered" : <number>,
  116. "Maximum page size seen" : <number>,
  117. "Minimum on-disk page image size seen" : <number>,
  118. "Number of pages never visited by eviction server" : <number>,
  119. "On-disk page image sizes smaller than a single allocation unit" : <number>,
  120. "Pages created in memory and never written" : <number>,
  121. "Pages currently queued for eviction" : <number>,
  122. "Pages that could not be queued for eviction" : <number>,
  123. "Refs skipped during cache traversal" : <number>,
  124. "Size of the root page" : <number>,
  125. "Total number of pages currently in cache" : <number>
  126. },
  127. "compression" : {
  128. "compressed pages read" : <number>,
  129. "compressed pages written" : <number>,
  130. "page written failed to compress" : <number>,
  131. "page written was too small to compress" : 1
  132. },
  133. "cursor" : {
  134. "bulk-loaded cursor-insert calls" : <number>,
  135. "close calls that result in cache" : <number>,
  136. "create calls" : <number>,
  137. "cursor operation restarted" : <number>,
  138. "cursor-insert key and value bytes inserted" : <number>,
  139. "cursor-remove key bytes removed" : <number>,
  140. "cursor-update value bytes updated" : <number>,
  141. "cursors reused from cache" : <number>,
  142. "insert calls" : <number>,
  143. "modify calls" : <number>,
  144. "next calls" : <number>,
  145. "open cursor count" : <number>,
  146. "prev calls" : <number>,
  147. "remove calls" : <number>,
  148. "reserve calls" : <number>,
  149. "reset calls" : <number>,
  150. "search calls" : <number>,
  151. "search near calls" : <number>,
  152. "truncate calls" : <number>,
  153. "update calls" : <number>
  154. },
  155. "reconciliation" : {
  156. "dictionary matches" : <number>,
  157. "fast-path pages deleted" : <number>,
  158. "internal page key bytes discarded using suffix compression" : <number>,
  159. "internal page multi-block writes" : <number>,
  160. "internal-page overflow keys" : <number>,
  161. "leaf page key bytes discarded using prefix compression" : <number>,
  162. "leaf page multi-block writes" : <number>,
  163. "leaf-page overflow keys" : <number>,
  164. "maximum blocks required for a page" : <number>,
  165. "overflow values written" : <number>,
  166. "page checksum matches" : <number>,
  167. "page reconciliation calls" : <number>,
  168. "page reconciliation calls for eviction" : <number>,
  169. "pages deleted" : <number>
  170. },
  171. "session" : {
  172. "object compaction" : <number>,
  173. },
  174. "transaction" : {
  175. "update conflicts" : <number>
  176. }
  177. },
  178. "nindexes" : <number>,
  179. "indexDetails" : {
  180. "_id_" : {
  181. "metadata" : {
  182. "formatVersion" : 8,
  183. "infoObj" : "{ \"v\" : 2, \"key\" : { \"_id\" : 1 }, \"name\" : \"_id_\", \"ns\" : \"test.restaurants\" }"
  184. },
  185. ...
  186. },
  187. ...
  188. },
  189. "indexBuilds" : [ // Available starting in MongoDB 4.2
  190. <string>,
  191. ],
  192. "totalIndexSize" : <number>,
  193. "indexSizes" : {
  194. "_id_" : <number>,
  195. "<indexName>" : <number>,
  196. ...
  197. },
  198. // ...
  199.  
  200. "scaleFactor" : <number> // Available starting in MongoDB 4.2
  201.  
  202. "ok" : <number>
  203. }

Output

  • collStats.ns
  • The namespace of the current collection, which follows the format[database].[collection].
  • collStats.size
  • The total uncompressed size in memory of all records in acollection. The size does notinclude the size of any indexes associated with the collection,which the totalIndexSize field reports.

The scale argument affects this value. Data compression does notaffect this value.

  • collStats.count
  • The number of objects or documents in this collection.
  • 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 fordocument storage. The scale argument affects thisvalue.

If collection data is compressed (which is the default forWiredTiger), thestorage size reflects the compressed size and may be smaller thanthe value for collStats.size.

storageSize does not include index size. SeetotalIndexSize for index sizing.

  • collStats.nindexes
  • The number of indexes on the collection. All collections have atleast one index on the _id field.

Starting in MongoDB 4.2, nindexes includes in itscount those indexes currently being built.

  • collStats.indexDetails

New in version 3.0.0.

A document that reports data from the WiredTigerstorage engine for each index in the collection. Other storage engines willreturn an empty document.

The fields in this document are the names of the indexes, while thevalues themselves are documents that contain statistics for theindex provided by the storage engine. These statistics are forinternal diagnostic use.

Starting in MongoDB 4.2, indexDetails includesdetails on indexes currently being built.

  • collStats.indexBuilds
  • An array that contains the names of the indexes that are currentlybeing built on the collection. Once an index build completes, theindex does not appear in the indexBuilds.

New in version 4.2.

  • collStats.totalIndexSize
  • The total size of all indexes. The scale argument affects thisvalue.

If an index uses prefix compression (which is the defaultfor WiredTiger), thereturned size reflects the compressed size for any such indexes whencalculating the total.

Starting in MongoDB 4.2, totalIndexSize includesin its total the size of those indexes currently being built.

  • collStats.indexSizes
  • This field specifies the key and size of every existing index onthe collection. The scale argument affects this value.

If an index uses prefix compression (which is the defaultfor WiredTiger), thereturned size reflects the compressed size.

Starting in MongoDB 4.2, indexSizes includessizes of indexes currently being built.

  • collStats.scaleFactor
  • The scale value used by the command.

If you had specified a non-integer scale factor, MongoDB uses theinteger part of the specified factor. For example, if you specify ascale factor of 1023.999, MongoDB uses 1023 as the scalefactor.

New in version 4.2.

  • collStats.capped
  • This field will be “true” if the collection iscapped.
  • collStats.max
  • Shows the maximum number of documents that may be present in acapped collection.
  • collStats.wiredTiger

New in version 3.0.0.

wiredTiger only appears when using theWiredTiger storage engine.

This document contains data reporteddirectly by the WiredTiger engine and other data for internaldiagnostic use.