Documentation

Collection Statistics

Collection Statistics

View detailed statistics for individual MongoDB collections with a comprehensive 4-tab interface. Monitor document counts, storage usage, index performance, cache statistics, and identify optimization opportunities for your collection.

Quick Start

Access collection statistics to analyze a specific collection's performance:

  1. In the sidebar, right-click on the collection you want to analyze
  2. Select Collection Statistics from the context menu
  3. The stats view opens with 4 tabs: Overview, Indexes, Cache, and Storage
  4. Navigate between tabs to explore different aspects of collection performance
  5. Enable Auto-refresh for real-time monitoring (refreshes every 30 seconds)
Collection Statistics interface showing tab navigation (Overview, Indexes, Cache, Storage) and the Overview tab with stat cards
Video COST02 Exploring Collection Statistics - Navigate through the 4-tab interface, view overview metrics, examine index details, and monitor cache performance

Tab Navigation

Collection statistics are organized into four specialized tabs, each focusing on a different aspect of collection performance:

  • Overview - Main collection metrics including document count, sizes, and storage breakdown
  • Indexes - Detailed index statistics, usage patterns, and size information for all indexes
  • Cache - WiredTiger cache statistics showing memory usage and performance metrics
  • Storage - Storage allocation, efficiency metrics, and disk space analysis

Click any tab to switch views. All tabs share the same refresh and auto-refresh controls.

Overview Tab

The Overview tab displays the most important collection metrics at a glance, with stat cards and storage breakdown charts.

Top Stat Cards

Card Metric Description
Documents Total document count Number of documents stored in the collection (stats.count)
Collection Size Uncompressed data size Total size of all documents before compression (stats.size)
Average Doc Size Average document size Average size per document (stats.avgObjSize)
Total Size Total disk footprint Storage size + index size (stats.totalSize)

Storage Breakdown Panel

Shows how storage is allocated across different components:

  • Data Size - Uncompressed document data size
  • Index Size - Total space consumed by all indexes
  • Free Space - Reclaimable space within allocated storage
  • Total - Sum of all storage components

Collection Info Panel

Displays additional collection metadata:

  • Indexes - Number of indexes defined on the collection (stats.nindexes)
  • Capped - Whether the collection is a capped collection (stats.capped)
  • Storage Engine - Always "WiredTiger" for modern MongoDB
  • Storage Efficiency - Percentage of storage actually used (excludes free space)

Indexes Tab

The Indexes tab provides detailed statistics for each index on the collection, helping you optimize query performance and manage index overhead.

Indexes tab showing a list of all indexes with their names, sizes, and statistics

Index Information Displayed

Metric Description
Index Name Name of the index (e.g., _id_, email_1, compound_index)
Index Size Disk space consumed by this index (from stats.indexSizes)
Index Type Type from index details (WiredTiger, btree, etc.)
URI WiredTiger internal URI for the index
Creation String WiredTiger creation configuration string

Note: The _id index is automatically created by MongoDB and cannot be deleted. All other indexes are user-defined.

Index Optimization Tips

  • Look for indexes with large sizes but low usage (check query plans to verify)
  • If index size approaches or exceeds data size, consider reviewing your indexing strategy
  • Compound indexes may be more efficient than multiple single-field indexes
  • Use covered queries where the index contains all fields needed by the query
Video COST04 Analyzing Index Performance - Review index sizes, identify unused indexes, optimize compound indexes, and improve query coverage

Cache Tab

The Cache tab displays WiredTiger cache statistics, showing how efficiently MongoDB is caching this collection's data and indexes in memory.

Cache tab showing WiredTiger cache statistics with memory usage metrics

Key Cache Metrics

Metric Source Description
Bytes in Cache wiredTiger.cache Current bytes cached for this collection in WiredTiger cache
Dirty Bytes wiredTiger.cache Modified pages in cache not yet written to disk (cumulative)
Bytes Read wiredTiger.cache Total bytes read into cache from disk
Bytes Written wiredTiger.cache Total bytes written from cache to disk
Pages Requested wiredTiger.cache Total page requests from the cache
Modified Pages Evicted wiredTiger.cache Dirty pages evicted from cache (indicates memory pressure)
Unmodified Pages Evicted wiredTiger.cache Clean pages evicted from cache

Cache Walk Statistics

Additional metrics from the cache walk subsystem (stats.wiredTiger.cache_walk):

  • Clean Pages in Cache - Unmodified pages currently cached
  • Dirty Pages in Cache - Modified pages not yet persisted
  • Total Pages in Cache - All pages currently held in memory
  • Current Eviction Generation - Internal WiredTiger metric for cache management
  • Average Page Size - Average size of cached pages

Interpreting Cache Statistics

  • High Evictions - May indicate insufficient cache size; consider increasing WiredTiger cache
  • High Dirty Bytes - Many uncommitted changes; normal during heavy writes, but sustained levels may indicate checkpoint issues
  • Low Bytes in Cache - Collection data isn't being cached effectively; check query patterns
  • High Read/Write Ratios - Shows disk I/O patterns; high values indicate cache misses

Storage Tab

The Storage tab focuses on disk space allocation, efficiency, and detailed storage metrics for the collection.

Storage tab showing storage size, free storage, efficiency percentage, and storage allocation breakdown

Storage Metrics

Metric Description
Storage Size Total allocated disk space for the collection (stats.storageSize)
Free Storage Reclaimable space within allocated storage (stats.freeStorageSize)
Storage Efficiency Percentage of allocated storage actually in use: (storageSize - freeStorageSize) / storageSize × 100

Storage Allocation Visualization

The storage allocation panel shows a breakdown of how disk space is used:

  • Data - Actual document data (blue indicator)
  • Indexes - Index storage (purple indicator)
  • Free Space - Reclaimable storage within allocated files (gray indicator)

Understanding Storage Efficiency

Storage efficiency indicates how well the allocated space is being utilized:

  • 90-100% - Excellent efficiency; very little wasted space
  • 70-90% - Good efficiency; normal for active collections
  • 50-70% - Moderate efficiency; consider monitoring for growth
  • Below 50% - Low efficiency; significant free space that could be reclaimed with compact

Note: Low efficiency often occurs after deleting many documents. Run the compact command during a maintenance window to reclaim space.

Auto-Refresh Feature

Enable the Auto-refresh checkbox to monitor collection statistics in real-time. When enabled:

  • Statistics refresh automatically every 30 seconds (default interval)
  • All tabs update with the latest data from the server
  • The refresh icon spins during data loading
  • Auto-refresh continues until you disable it or close the tab

Use Cases for Auto-Refresh

  • Monitoring collection growth during bulk inserts or imports
  • Tracking cache statistics during query performance tuning
  • Watching storage efficiency after running maintenance operations
  • Observing index size changes during index builds

Available Actions

Refresh

Click the Refresh button to manually update statistics for the collection. This executes a new db.collection.stats() command on the server.

Enable Auto-Refresh

Check the Auto-refresh checkbox to enable automatic refreshing every 30 seconds. Useful for monitoring ongoing operations.

Switch Tabs

Click on any of the four tabs (Overview, Indexes, Cache, Storage) to view different aspects of collection statistics.

Pro Tips

  1. Compare Tabs: Use Overview for quick health checks, Indexes to optimize queries, Cache for memory tuning, and Storage for capacity planning.
  2. Watch Index Growth: If total index size exceeds collection size, you may have too many or overly large indexes. Review index usage with query plans.
  3. Cache Monitoring: High page evictions on the Cache tab indicate memory pressure. Consider increasing WiredTiger cache size if possible.
  4. Storage Efficiency: Low efficiency (below 70%) after deletions means you can reclaim space with db.collection.compact() during off-peak hours.
  5. Average Doc Size: Use average document size to estimate storage needs for future growth. Large averages may indicate unnecessary data or lack of compression.
  6. Auto-Refresh During Ops: Enable auto-refresh when running bulk operations, index builds, or imports to monitor progress and impact in real-time.

Understanding the Stats Command

VisualLeaf executes the following MongoDB command to retrieve collection statistics:

db.collection.stats({ scale: 1 })

The response includes detailed WiredTiger storage engine statistics for the collection, indexes, cache, and more.

Performance Considerations

  • Lightweight Operation - Collection stats reads metadata and doesn't scan documents
  • Brief Lock - Acquires a short read lock; safe to run on production
  • Cache Friendly - Stats are often served from WiredTiger's metadata cache
  • Auto-Refresh Impact - Running every 30 seconds has minimal performance impact

Ready to try VisuaLeaf?

Download and start managing your MongoDB databases with ease.

Download Free Trial