# MongoServerError: Shard key range deletion conflict: range [minKey, maxKey) on shard 'shard01' has pending deletions

- **ID:** `mongodb/shard-key-range-deletion-conflict`
- **Domain:** mongodb
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A chunk migration or drop command failed because the target range has pending deletion tasks from a previous migration, causing a lock conflict.

## Version Compatibility

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

## Workarounds

1. **Wait for pending deletions to complete by monitoring the `config.chunks` collection: `db.getSiblingDB('config').chunks.find({ shard: 'shard01', lastmodEpoch: ... })` and check for `pending` flags; retry after 60 seconds.** (75% success)
   ```
   Wait for pending deletions to complete by monitoring the `config.chunks` collection: `db.getSiblingDB('config').chunks.find({ shard: 'shard01', lastmodEpoch: ... })` and check for `pending` flags; retry after 60 seconds.
   ```
2. **Manually clear pending range deletions using the internal command: `db.adminCommand({ _configsvrCommitRangeDeletion: 'config.system.chunks', range: { min: minKey, max: maxKey }, shard: 'shard01' })` (requires admin privileges and caution).** (85% success)
   ```
   Manually clear pending range deletions using the internal command: `db.adminCommand({ _configsvrCommitRangeDeletion: 'config.system.chunks', range: { min: minKey, max: maxKey }, shard: 'shard01' })` (requires admin privileges and caution).
   ```
3. **Disable the balancer temporarily: `sh.stopBalancer(60000)` and then manually force a cleanup with `db.adminCommand({ cleanupOrphaned: 'mydb.mycoll', startingFromKey: minKey })` on the affected shard.** (80% success)
   ```
   Disable the balancer temporarily: `sh.stopBalancer(60000)` and then manually force a cleanup with `db.adminCommand({ cleanupOrphaned: 'mydb.mycoll', startingFromKey: minKey })` on the affected shard.
   ```

## Dead Ends

- **** — Pending deletions are internal metadata (range deletion tasks), not user documents; manual deletes do not affect them and may corrupt shard metadata. (90% fail)
- **** — Restarting clears in-memory state but the pending deletion tasks are persisted in config server metadata; they will resume after restart. (85% fail)
- **** — Splitting a range with pending deletions can cause orphaned documents and inconsistent metadata; the operation is rejected by the balancer. (80% fail)
