How to Fix MongoDB Error 70 (ShardNotFound)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mongodb error 70 when a router asks for a shard that is missing. You fix this ShardNotFound failure by refreshing router metadata and checking your shard list. Sharded clusters split large data sets across many servers. Query routers track where each piece of data lives. When a shard leaves the cluster or changes names, routers can lose track. The database then stops the query and returns code 70. What causes mongodb error 70 in a sharded cluster In the database engine, code 70 carri

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 get mongodb error 70 when a router asks for a shard that is missing. You fix this ShardNotFound failure by refreshing router metadata and checking your shard list.

Sharded clusters split large data sets across many servers. Query routers track where each piece of data lives. When a shard leaves the cluster or changes names, routers can lose track. The database then stops the query and returns code 70.

What causes mongodb error 70 in a sharded cluster

In the database engine, code 70 carries the name ShardNotFound. It means a router or config server looked up a shard name that does not exist. This problem happens in three main ways during cluster operations.

First, a team member might remove a shard during maintenance. If a query router still holds old routing tables, it sends reads to the old shard. The config server rejects that request and returns ShardNotFound.

Second, manual metadata edits can break the shard map. If an operator types the wrong shard name during a chunk move, the cluster cannot find the target. The command fails right away with code 70.

Third, network splits can isolate config servers from query routers. When routers cannot refresh their cache, they use stale shard records. Apps then hit errors until the network path recovers and caches update.

How to diagnose and fix ShardNotFound safely

Start by checking the active shard list on your config servers. Compare the shard names in your cluster map against the error log message. Look for typos, removed nodes, or incomplete shard drains.

Do not give every engineer full cluster admin rights during an outage. MongoDB grants access through roles that define allowed actions on specific resources. A role applies to its target database and can limit actions down to a single collection.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

For initial checks, use the built-in read role on the database. The read role lets engineers run find, listCollections, listIndexes, dbStats, and collStats actions. It blocks insert, update, remove, and dropCollection actions so nobody deletes data by mistake.

Note that MongoDB Atlas users have different built-in roles than self-hosted users. Still, both setups build their roles from the same privilege actions. Pick the smallest role that lets your team inspect the shard map.

Once you find the stale route, flush the router cache on the affected query nodes. This step forces the router to pull fresh shard records from the config server. Wait a few seconds and test a read query from your app.

How to prevent shard routing failures in production

Most ShardNotFound incidents happen after rushed cluster changes. You can stop these errors by standardizing how your team drains and removes shards. Always let the balancer finish moving data chunks before you shut down a shard host.

Keep normal app accounts on strict roles too. Use the readWrite role only for services that must change data. That role adds insert, update, remove, createCollection, and index actions on top of read rights. It still keeps app accounts away from cluster routing settings.

Also watch your router logs after any cluster scale event. If a router fails to refresh its shard map, restart or flush that router right away. Fast cache refreshes keep stale shard names from breaking live user traffic.

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 does MongoDB error code 70 mean?

Error code 70 means ShardNotFound in a sharded cluster. The cluster router tried to reach a shard ID that does not exist in the config database.

Does fixing ShardNotFound require dropping collections?

No, you do not need to drop collections or delete data to fix code 70. You fix it by refreshing router metadata caches and verifying active shard names.

Can a read-only user trigger mongodb error 70?

Yes, a user with the read role can hit this error during normal find queries. If the query router points to a removed shard, any read request to that shard fails.

The query runs. The emails stay hidden.