# MongoServerError: 无法更新系统索引 'system.indexes'

- **ID:** `database/mongodb-cannot-update-system-index`
- **领域:** database
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

尝试使用写操作直接修改系统集合（如 system.indexes），MongoDB 出于安全性和一致性原因禁止这样做。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## 解决方案

1. ```
   Use the proper MongoDB command to manage indexes, such as createIndex() or dropIndex(), which handle system collection updates internally:
db.myCollection.createIndex({ field: 1 })
   ```
2. ```
   If you need to modify system collection behavior, use documented features like the 'system.profile' collection via db.setProfilingLevel() instead of direct writes.
   ```

## 无效尝试

- **Trying to drop and recreate the system.indexes collection** — MongoDB prevents dropping system collections; this operation will fail with a similar error. (95% 失败率)
- **Using db.runCommand({collMod: 'system.indexes', ...})** — collMod is not supported for system collections; MongoDB returns an error. (90% 失败率)
