How to Fix MongoDB Error 381 (ReshardingCoordinatorServiceConflictingOperationInProgress)
You see mongodb error 381 when an internal resharding task clashes with another active job. You can fix it by waiting for the current task to end before you retry. In the database catalog, this failure is named ReshardingCoordinatorServiceConflictingOperationInProgress. It carries the InternalOnly category tag. That tag means the database engine uses this code for internal coordination across nodes. When two cluster changes overlap, the coordinator stops the second request right away. This stop
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 381 when an internal resharding task clashes with another active job. You can fix it by waiting for the current task to end before you retry.
In the database catalog, this failure is named ReshardingCoordinatorServiceConflictingOperationInProgress. It carries the InternalOnly category tag. That tag means the database engine uses this code for internal coordination across nodes. When two cluster changes overlap, the coordinator stops the second request right away. This stop protects your sharded data from corruption during data movement.
What causes mongodb error 381 in your cluster
A sharded cluster uses a coordinator service to move data across shards. When a resharding job starts, this service locks the target collection state. If another command tries to start a conflicting task, the coordinator rejects it. The cluster then logs mongodb error 381 to signal the conflict.
Common triggers include running two resharding requests at the exact same time. Automated scripts or admin tools might also send overlapping cluster commands by mistake. A network drop can force a node to retry a task too early. Because the code is marked InternalOnly, client apps rare see it directly. Instead, it shows up in internal server logs or admin command outputs.
How to diagnose and fix the conflict safely
Start by checking which cluster tasks are running right now. Look at your database logs to find the active resharding coordinator process. Do not restart shard nodes or kill internal threads to clear the lock. Forcing a stop can leave metadata in a broken state across shards.
Wait for the active resharding work to finish on its own. Once the coordinator finishes its job, the lock clears without manual intervention. If a task is stuck, use standard admin commands to abort it cleanly. After the cluster state is idle, run your planned command again.
Service-to-Service Authentication + MongoDB Authentication & Authorization: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
When you check production state, use least privilege accounts at all times. MongoDB grants access through role-based authorization on defined resources. A role applies to its defined database and can work at the collection level. Give your team the built-in read role for initial checks. The read role allows find, listCollections, listIndexes, dbStats, collStats, and changeStream actions. It blocks insert, update, remove, and dropCollection actions on your data. Avoid granting the readWrite role during a simple status check. The readWrite role adds insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection actions.
How to prevent future resharding conflicts
Good scheduling stops overlapping cluster tasks before they start. Make sure your deployment scripts check for active migrations before sending new requests. Run only one major resharding job at a time on your cluster.
You should also limit who can trigger cluster-wide changes in production. Notice that MongoDB Atlas users have different built-in roles than self-hosted users. Still, both systems build their roles from the same set of privilege actions. Keep admin roles away from daily debugging accounts so nobody starts a conflict.
Inspect MongoDB wire traffic in flight
Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.
First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.
Frequently asked questions
What is the official name for mongodb error 381?
The official name for code 381 is ReshardingCoordinatorServiceConflictingOperationInProgress. It belongs to the InternalOnly error category in the database engine.
Can a normal read query trigger this resharding error?
No, standard read queries do not trigger this coordinator conflict. It only happens when internal cluster tasks or resharding operations overlap.
Should I grant readWrite access to debug error 381?
No, you do not need readWrite access to inspect cluster logs or stats. Use a role with read actions like dbStats and collStats to check status safely.
Related guides
In this post