# MongoServerError: Cannot update system index 'system.indexes'

- **ID:** `database/mongodb-cannot-update-system-index`
- **Domain:** database
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

An attempt was made to directly modify a system collection (like system.indexes) using a write operation, which is forbidden in MongoDB for security and consistency reasons.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## Workarounds

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 })** (95% success)
   ```
   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.** (85% success)
   ```
   If you need to modify system collection behavior, use documented features like the 'system.profile' collection via db.setProfilingLevel() instead of direct writes.
   ```

## Dead Ends

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