# MongoServerError: 在命名空间 mydb.mycoll 的块迁移期间检测到孤立文档

- **ID:** `mongodb/sharded-cluster-orphan-documents`
- **领域:** mongodb
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

由于并发写入或迁移清理失败，块迁移留下了不属于新分片范围的文档。

## 版本兼容性

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

## 解决方案

1. ```
   Use the cleanupOrphaned command on the affected shard to remove orphan documents: db.adminCommand({ cleanupOrphaned: 'mydb.mycoll' }).
   ```
2. ```
   Temporarily disable the balancer (sh.stopBalancer()) and manually re-migrate the chunk to ensure consistent range coverage.
   ```
3. ```
   Verify shard key distribution and adjust chunk boundaries using splitChunk to isolate orphan documents.
   ```

## 无效尝试

- **** — Deletion without verifying shard key ranges can cause data loss. (80% 失败率)
- **** — Orphans persist after restart unless the balancer re-migrates or cleanup runs. (90% 失败率)
- **** — Cleanup may conflict with ongoing balancer operations, requiring repeated runs. (50% 失败率)
