$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
