# MongoServerError: orphan documents detected during chunk migration on namespace mydb.mycoll

- **ID:** `mongodb/sharded-cluster-orphan-documents`
- **Domain:** mongodb
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

Chunk migration left behind documents that do not belong to the new shard range due to concurrent writes or a failed migration cleanup.

## Version Compatibility

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

## Workarounds

1. **Use the cleanupOrphaned command on the affected shard to remove orphan documents: db.adminCommand({ cleanupOrphaned: 'mydb.mycoll' }).** (80% success)
   ```
   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.** (85% success)
   ```
   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.** (70% success)
   ```
   Verify shard key distribution and adjust chunk boundaries using splitChunk to isolate orphan documents.
   ```

## Dead Ends

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