<!-- llms-explorer concept facts · https://llms-explorer.com/tree/plancachesize-and-plancachestats/ · pack 2026-10-22 · ~822 tokens -->

# planCacheSize and $planCacheStats

> Source-anchored research for planCacheSize and $planCacheStats. Run status: COMPLETED.

Parent: [MongoDB Explain Plans, Query Planner and Plan Cache](https://llms-explorer.com/tree/mongodb-explain-plans-query-planner-and-plan-cache/) · 4 facets · 8 facts · page: https://llms-explorer.com/tree/plancachesize-and-plancachestats/

## Definitions

- `$planCacheStats` is a collection-scoped aggregation stage that must appear first and returns one document per cache entry; its output can include `isActive`, `works`, and `estimatedSizeBytes` for inspecting entries and their estimated per-entry sizes. (high confidence) (verified as of 2026-10-22) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/plancachestats/)
- The `estimatedSizeBytes` field is an estimate for one cache entry, not an exact total for the whole plan cache. MongoDB's serializer populates that output field from the entry's `estimatedEntrySizeBytes` value. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md)

## How it works

- The plan cache is in memory and per collection, is discarded when `mongod` restarts, and uses LRU replacement to remove the least recently accessed entry. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/query-plans/)

## Measurements and reference values

- Starting in MongoDB 6.3, `planCacheSize` is a `mongod` string parameter with a 5% default; it accepts a percentage of system total physical memory or a fixed MB/GB amount and supports startup and runtime changes. MongoDB documents it as applying only to the slot-based query execution engine's plan cache. (high confidence) (verified as of 2026-10-22) — [source](https://www.mongodb.com/docs/manual/reference/parameters/)
- Starting in MongoDB 5.0, when cumulative plan-cache size across collections exceeds 0.5 GB, MongoDB stores later entries without `createdFromQuery`, `cachedPlan`, `creationExecStats`, or `candidatePlanScores`; `$planCacheStats` also documents `estimatedSizeBytes` as an individual entry estimate. (high confidence) (verified as of 2026-10-22) — [source](https://www.mongodb.com/docs/manual/core/query-plans/)

## Facts and statements

- Plan cache contents are local to each `mongod` and can differ between members. By default, `$planCacheStats` follows read preference and returns data from one member per replica set; on sharded clusters, `allHosts: true` broadcasts to all nodes for affected shards. The `allHosts` option was added in MongoDB 7.1. (high confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md)
- Per-entry inspection and aggregate hit/miss monitoring provide different views: DataDog's MongoDB integration release 6.10.0, dated 2024-09-05, added plan cache hit and miss rate metrics for MongoDB 7.0 and later. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md)
- Increasing `planCacheSize` can let the planner retain more query shapes and may improve query performance, but it also increases memory use. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/parameters/)
