# MongoServerError：查询形状的计划缓存条目已失效但无法重新规划：内部错误

- **ID:** `mongodb/plan-cache-invalidation-failed`
- **领域:** mongodb
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

由于索引更改或数据分布变化，查询形状的计划缓存条目失效，但查询规划器因缓存元数据损坏或索引缺失而无法生成新计划。

## 解决方案

1. ```
   Run db.collection.getPlanCache().clear() followed by db.collection.createIndex() for the missing index, then re-execute the query to force a fresh plan.
   ```
2. ```
   Upgrade to MongoDB 7.0+ where plan cache invalidation is more robust; if not possible, set internalQueryPlanCacheSize to 0 in the configuration to disable caching temporarily.
   ```

## 无效尝试

- **** — Restarting mongod clears the plan cache temporarily, but the error reoccurs if the underlying cause (e.g., missing index or stale statistics) isn't addressed. (90% 失败率)
- **** — Manually running db.collection.getPlanCache().clear() may not help if the query shape is still cached in the server's internal structures; the error persists. (70% 失败率)
