13388
MongoDBERRORShardingHIGH confidence

Sharding configuration is stale

What this means

This error occurs in a sharded cluster when a `mongos` instance has an outdated view of the cluster's sharding metadata compared to the config servers. It's a safety mechanism to prevent operations based on stale information.

Why it happens
  1. 1A `mongos` has not successfully refreshed its view of the sharding config from the config servers
  2. 2Network issues are preventing a `mongos` from communicating with the config servers
  3. 3A chunk migration or other sharding metadata change occurred, and the `mongos` has not yet updated its cache
  4. 4High load on the config servers, delaying their responses to the `mongos`
How to reproduce

A client sends a query through a `mongos` immediately after a chunk migration, but the `mongos`'s cached routing table is not yet updated.

trigger — this will error
trigger — this will error
// This error is not directly triggered by a single user command.
// It is a result of timing and state within a sharded cluster.
// 1. A chunk is migrated from shardA to shardB.
// 2. A query for data in that chunk arrives at a mongos.
// 3. The mongos's cache still says the chunk is on shardA.
// 4. The mongos forwards the query to shardA, which rejects it because it no longer owns the chunk.
// 5. shardA returns a stale config error to the mongos.

expected output

MongoServerError: StaleConfig: ...

Fix 1

Rely on Automatic Retry

WHEN Using a modern MongoDB driver.

Why this works

When a `mongos` receives a stale config error, it automatically refreshes its metadata cache from the config servers and retries the operation. Modern drivers will seamlessly handle this process. For the application, this should be a transient, automatically-resolved error.

Fix 2

Investigate Network/Config Server Health

WHEN The error is persistent and not resolving automatically.

Why this works

If stale config errors are frequent and causing noticeable application failures, it points to a deeper issue. Investigate network connectivity between your `mongos` instances and your config servers. Check the health and load of the config server replica set.

What not to do

✕ Connect clients directly to individual shards to bypass the error

This breaks the entire model of a sharded cluster. The `mongos` is the correct entry point, and connecting directly to shards can lead to incomplete query results and data inconsistency.

Sources
Official documentation ↗

mongodb/mongo src/mongo/base/error_codes.yml

Sharded Cluster Query Routing ↗

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MongoDB errors