Error
Error Code: 193

MongoDB Error 193: Sharding Not Configured

📦 MongoDB
📋

Description

This error indicates that a sharding-specific operation was attempted on a MongoDB deployment where sharding has not been enabled or properly initialized. It typically occurs when trying to execute sharding commands or access sharded collections on a standalone instance or a replica set.
💬

Error Message

No Sharding Enabled
🔍

Known Causes

3 known causes
⚠️
Sharding Not Initialized
The MongoDB cluster has not been configured and initialized as a sharded cluster.
⚠️
Standalone or Replica Set Deployment
The MongoDB instance you are connected to is a standalone server or a replica set, which inherently does not support sharding.
⚠️
Connected to mongod Instead of mongos
In a sharded cluster, operations requiring sharding must be routed through a `mongos` router, not directly to a `mongod` shard member.
🛠️

Solutions

4 solutions available

1. Verify Sharding Configuration Status easy

Check if sharding is actually enabled on your MongoDB deployment.

1
Connect to your MongoDB deployment using the `mongosh` shell.
mongosh
2
Run the `sh.status()` command to check the sharding status. If sharding is not enabled, this command will indicate that.
sh.status()
3
If the output clearly states that sharding is not enabled and you intended to use sharding, you will need to proceed with configuring it. If you did not intend to use sharding, this error might be misleading or indicate an issue with a specific operation that expects sharding.

2. Enable Sharding for a Specific Database medium

Configure sharding for a database if it's not already enabled.

1
Connect to your MongoDB deployment using `mongosh`.
mongosh
2
Use the `sh.enableSharding()` command, replacing `your_database_name` with the actual name of the database you want to shard.
sh.enableSharding('your_database_name')
3
After enabling sharding for the database, you will need to shard individual collections within that database by defining a shard key.
sh.shardCollection('your_database_name.your_collection_name', { your_shard_key_field: 1 })

3. Start `mongos` Instances for a Sharded Cluster medium

Ensure that `mongos` routers are running if you are attempting to access a sharded cluster.

1
On the machine(s) designated as `mongos` routers, start the `mongos` process. Replace `config_server_connection_string` with the connection string to your config servers (e.g., `mongodb://cfg1.example.net:27019,cfg2.example.net:27019,cfg3.example.net:27019`).
mongos --configdb <config_server_connection_string>
2
Verify that the `mongos` processes are running and accessible. You can check the MongoDB logs for any errors during startup.
3
Connect to the `mongos` instance(s) instead of directly to a `mongod` shard server to interact with your sharded cluster.
mongosh --host <mongos_host> --port <mongos_port>

4. Review Deployment Architecture and Intent advanced

Confirm if your deployment should be sharded or if sharding is a misunderstanding.

1
Evaluate your MongoDB deployment's purpose and data volume. Sharding is typically used for large datasets or high write throughput, not for smaller, single-server deployments.
2
If you are running a standalone `mongod` instance or a replica set without any `mongos` routers, sharding is not enabled by design. The error might be triggered by an application or tool that incorrectly assumes sharding is configured.
3
If sharding is not intended, ensure your applications are connecting directly to the `mongod` instances or the primary of a replica set and not trying to use sharding commands or connect to non-existent `mongos` routers.
🔗

Related Errors

5 related errors