# MongoServerError: IndexKeyTooLarge: index key for compound index 'idx_1_2_3' on namespace test.events has key size 1050 bytes, which exceeds the maximum index key size of 1024 bytes

- **ID:** `mongodb/index-key-too-large-for-compound-index`
- **Domain:** mongodb
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

The combined size of indexed fields in a document exceeds MongoDB's 1024-byte index key limit, often due to large string or array values.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| mongodb-5.0 | active | — | — |
| mongodb-6.0 | active | — | — |
| mongodb-7.0 | active | — | — |
| mongodb-8.0 | active | — | — |

## Workarounds

1. **Reduce the size of indexed fields by truncating long strings or using smaller data types (e.g., ObjectId instead of string IDs).** (85% success)
   ```
   Reduce the size of indexed fields by truncating long strings or using smaller data types (e.g., ObjectId instead of string IDs).
   ```
2. **Use a partial index that only indexes documents with smaller field values to avoid the limit.** (80% success)
   ```
   Use a partial index that only indexes documents with smaller field values to avoid the limit.
   ```
3. **Split the compound index into separate indexes and use $or queries to combine them, though this may affect performance.** (70% success)
   ```
   Split the compound index into separate indexes and use $or queries to combine them, though this may affect performance.
   ```

## Dead Ends

- **** — Increasing the index key limit is not possible; it is a hard limit in MongoDB. (50% fail)
- **** — Dropping the compound index and creating multiple single-field indexes may degrade query performance for multi-field queries. (50% fail)
- **** — Using a hashed index on all fields reduces query flexibility and does not support range queries. (50% fail)
