liveBook · Manning

collStats

As explained in MongoDB 8.0 in Action, Third Edition

collStats is a MongoDB command that returns document counts, data size, index counts, and related statistics for a collection.

collStats is a MongoDB diagnostic command for examining one collection’s document count, data size, index count, index performance, and related resource statistics. Use it to monitor collection health, evaluate storage use, and identify targets for performance or indexing improvements. section 21.2.3

Use collStats when you need to:

  • Inspect collection-level storage and document statistics. section 21.2.3
  • Review index counts and performance while investigating inefficient resource use. section 21.2.3
  • Complement database-wide dbStats results with more focused collection-level detail. section 21.2.3

Inspect one collection

Run `db.runCommand({ collStats: "collection_name" })`. Review the returned document for collection size, document count, index counts, and related performance information. Use those measurements to identify storage or indexing areas that may need optimization. section 21.2.3

db.runCommand({ collStats: "collection_name" })

The command listing provides a copyable collStats invocation for a named collection. section 21.2.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains the command’s purpose and returned statistic categories without descending into command internals or output interpretation procedures.
Examples
Uses db.runCommand({ collStats: "collection_name" }) to inspect a named collection.
What you can do after
Diagnose collection resource use and identify storage or indexing optimization targets from returned statistics.
How it connects
Connects collection diagnostics with dbStats, serverStatus, currentOp, top, indexing, sharding, and Atlas monitoring.

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.