# MongoServerError：分片键范围删除冲突：分片'shard01'上的范围[minKey, maxKey)有待处理的删除操作

- **ID:** `mongodb/shard-key-range-deletion-conflict`
- **领域:** mongodb
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

由于目标范围存在先前迁移的待处理删除任务，导致块迁移或删除命令失败，引发锁冲突。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| mongodb 6.0 | active | — | — |
| mongodb 7.0 | active | — | — |
| mongodb 8.0 | active | — | — |

## 解决方案

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.
   ```
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).
   ```
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.
   ```

## 无效尝试

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