How to Fix MongoDB Error 406 (MigrationBlockingOperationCoordinatorCleaningUp)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 406 when a shard cleans up after a blocked migration. To fix this issue, let the cleanup finish and retry your database operation. The official name for this issue is MigrationBlockingOperationCoordinatorCleaningUp. The database engine puts this code in the RetriableError category. This means your app can safely send the failed request again. You do not need to restart the cluster or change your data. What causes mongodb error 406 in your cluster Sharded clusters move d

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see mongodb error 406 when a shard cleans up after a blocked migration. To fix this issue, let the cleanup finish and retry your database operation.

The official name for this issue is MigrationBlockingOperationCoordinatorCleaningUp. The database engine puts this code in the RetriableError category. This means your app can safely send the failed request again. You do not need to restart the cluster or change your data.

What causes mongodb error 406 in your cluster

Sharded clusters move data chunks between shards to keep storage balanced. During a move, a coordinator tracks operations that might block the migration. Sometimes a write or admin task conflicts with this chunk movement.

When the conflict ends, the coordinator must clean up its internal state. If a new request arrives during this short cleanup phase, the shard rejects it. The database then returns code 406 to the client driver.

High write traffic on a single collection makes this error happen more often. Large transactions that span multiple documents can also delay the cleanup worker. Network pauses between the primary shard and replica nodes add further delay. Until the coordinator finishes its state reset, conflicting tasks cannot run.

How to check and fix the failure safely

First, check if your client driver retries failed operations on its own. Since code 406 is a retriable error, modern drivers should repeat the request. If your app still fails, add a short wait before retrying in your code.

Next, inspect the cluster logs to see why the cleanup takes so long. Look for slow disk writes or high lock wait times on the shard. When engineers check the database, do not give them full admin rights.

MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

MongoDB controls access through roles that grant actions on specific resources. A role applies to its defined database and works down to the collection level. Give your team the built-in read role to check collection and database stats. This role allows actions like find, listCollections, listIndexes, dbStats, and collStats.

The read role leaves out actions that change data, like insert, update, or remove. It also blocks dropCollection so no one deletes a table by mistake. If an engineer must fix data or indexes, use the readWrite role instead. That role adds insert, update, remove, createIndex, and dropIndex for that database.

You should also protect sensitive user fields when teams read collection data. Data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs. This keeps private values safe while your team checks migration bottlenecks.

If error 406 keeps happening, look at your balancer schedule. Run heavy batch updates during hours when the chunk balancer is idle. Splitting large bulk writes into smaller batches also helps the coordinator finish faster. Once the lock clears, normal shard traffic will resume right away.

Add command guardrails and field masking beside MongoDB

Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.

Frequently asked questions

Is mongodb error 406 a permanent database failure?

No, code 406 is a temporary state in the RetriableError category. Once the coordinator finishes its cleanup task, the shard accepts requests again.

Can I fix code 406 by restarting the shard server?

Do not restart the shard to clear this error. A restart interrupts the cleanup process and causes a longer outage for your app.

What role should engineers use to inspect collection stats during this error?

Assign the built-in read role on the affected database. It allows dbStats and collStats actions without granting permission to change or delete data.

The query runs. The emails stay hidden.