liveBook · Manning

$planCacheStats

As explained in MongoDB 8.0 in Action, Third Edition

$planCacheStats is a MongoDB aggregation pipeline stage that returns query plan cache entries and their statistics.

$planCacheStats is a MongoDB aggregation pipeline stage that returns query plan cache entries and their statistics. It complements explain(), which examines how MongoDB plans or executes a specific query; $planCacheStats instead provides information about the collection’s cached plans. section 7.1.1

Use the surrounding plan-cache guidance to interpret and manage the information:

  • Treat the stage as an operational inspection tool for understanding cached query plans and diagnosing query-efficiency problems. section 7.1.1
  • Remember that dropping indexes or collections resets the plan cache. section 7.1.2
  • Clear all entries with PlanCache.clear(), or selectively remove entries with PlanCache.clearPlansByQuery(). section 7.1.2
  • Interpret entry sizes as approximate byte counts; from MongoDB 5.0, debug information is omitted from new entries when combined plan-cache size exceeds 0.5 GB. section 7.1.2

For query-level execution details, use explain() with queryPlanner, executionStats, or allPlansExecution. Those outputs expose stages such as IXSCAN and FETCH, whereas $planCacheStats focuses on cached plan entries. section 7.1.1

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains the stage’s purpose and cache caveats, but does not show its aggregation syntax or returned document fields.
Examples
Uses explain() examples showing IXSCAN, FETCH, winning plans, and execution statistics as adjacent diagnostic context.
What you can do after
Diagnose query-efficiency problems by inspecting cached plan entries alongside query execution plans.
How it connects
Connects query plan cache information with aggregation pipelines, explain(), indexes, and query execution plans.

Related concepts

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.