Error
Error Code:
70
MongoDB Error 70: Shard Not Found
Description
MongoDB Error 70, 'Shard Not Found', indicates that a `mongos` query router cannot locate a required shard in the sharded cluster. This typically occurs when a shard is offline, has been improperly removed, or the cluster's configuration metadata is inconsistent.
Error Message
Shard Not Found
Known Causes
4 known causesShard Node Unavailable
A `mongod` instance or an entire shard replica set is offline or unreachable by the `mongos` router.
Inconsistent Cluster Metadata
The configuration servers hold incorrect or outdated information about the active shards in the cluster.
Network Reachability Issues
`mongos` cannot establish a connection to the shard due to network partitions, firewall rules, or incorrect IP/port configurations.
Improper Shard Removal
A shard was removed from the cluster without following proper de-sharding procedures, leaving its metadata inconsistent.
Solutions
3 solutions available1. Verify Shard Registration in Config Servers medium
Ensure the shard is correctly registered and visible to the config servers.
1
Connect to one of your MongoDB config servers using the `mongo` shell.
mongo --host <config_server_host>:<config_server_port>
2
Query the `config.shards` collection to list all registered shards.
db.shards.find().pretty()
3
Compare the output with your expected list of shards. If the shard reporting the error is missing or has an incorrect hostname/port, it needs to be re-added.
text
4
If the shard is missing, add it back using the `sh.addShard()` command. Replace `<shard_name>` and `<shard_host>` with the actual values.
sh.addShard("<shard_name>@<shard_host>:<shard_port>")
5
If the shard is present but has incorrect details, you might need to remove and re-add it. First, remove the incorrect shard entry.
sh.removeShard("<shard_name>")
6
Then, add the shard back with the correct details.
sh.addShard("<shard_name>@<shard_host>:<shard_port>")
2. Check Shard Server Status easy
Confirm that the shard server itself is running and accessible.
1
Attempt to connect to the shard server directly using the `mongo` shell.
mongo --host <shard_host>:<shard_port>
2
If the connection fails, verify that the `mongod` process is running on the shard server.
sudo systemctl status mongod
3
If the `mongod` process is not running, start it.
sudo systemctl start mongod
4
Ensure that there are no firewall rules blocking access to the shard server's MongoDB port.
text
3. Restart Sharding Services easy
A restart can resolve transient network or service issues affecting shard discovery.
1
Gracefully shut down the `mongod` process on the affected shard server.
sudo systemctl stop mongod
2
Wait for a short period (e.g., 30 seconds) to ensure all processes have terminated.
text
3
Start the `mongod` process on the shard server again.
sudo systemctl start mongod
4
Monitor the MongoDB logs on both the shard server and the config servers for any new errors.
text