# Sharding not enabled for db- 2shards- 3-configserv 3-mongos

**URL:** <https://forums.percona.com/t/sharding-not-enabled-for-db-2shards-3-configserv-3-mongos/26983>\
**Category:** Percona Operator for MongoDB\
**Tags:** percona, mongodb\
**Created:** [December 6, 2023, 12:42pm UTC](https://forums.percona.com/t/sharding-not-enabled-for-db-2shards-3-configserv-3-mongos/26983 "2023-12-06T12:42:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![preetsb86](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@preetsb86](https://forums.percona.com/u/preetsb86)\
**Post date:** [December 6, 2023, 12:42pm UTC](https://forums.percona.com/t/sharding-not-enabled-for-db-2shards-3-configserv-3-mongos/26983/1 "2023-12-06T12:42:06Z")

</div>

## Description:

sharding not enabled for db error while sharding on the collection .

## Steps to Reproduce:

sh.enableSharding(“shardemo1”)  
db.createCollection(“movies”)  
var shardKey = { “title”: “hashed” }  
db.movies.createIndex(shardKey)  
sh.shardCollection( “shardemo1.movies”, shardKey)  
mongos\> sh.shardCollection( “shardemo1.movies”, shardKey)  
{  
“ok” : 0,  
**“errmsg” : “sharding not enabled for db shardemo1”,**  
“code” : 20,  
“codeName” : “IllegalOperation”,  
“$clusterTime” : {  
“clusterTime” : Timestamp(1701864038, 9),  
“signature” : {  
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),  
“keyId” : NumberLong(0)  
}  
},  
“operationTime” : Timestamp(1701864038, 5)

## Version:

db-version-6.0.9-7  
operator version - crVersion: 1.15.0

## Logs:

{“t”:{“$date”:“2023-12-06T12:00:44.398+00:00”},“s”:“D1”, “c”:“SHARDING”, “id”:22772, “ctx”:“conn296204”,“msg”:“Exception thrown while processing command”,“attr”:{“db”:“admin”,“head  
erId”:3,“error”:“ClientDisconnect: operation was interrupted”}}  
{“t”:{“$date”:“2023-12-06T12:00:44.398+00:00”},“s”:“I”, “c”:“COMMAND”, “id”:51803, “ctx”:“conn296204”,“msg”:“Slow query”,“attr”:{“type”:“command”,“ns”:“admin.$cmd”,“command”:{“he  
llo”:1,“helloOk”:true,“topologyVersion”:{“processId”:{“$oid”:“656f256910f846fbd896cc2c”},“counter”:0},“maxAwaitTimeMS”:10000,“$db”:“admin”},“numYields”:0,“ok”:0,“errMsg”:“operation w  
as interrupted”,“errName”:“ClientDisconnect”,“errCode”:279,“reslen”:242,“remote”:“127.0.0.1:50974”,“protocol”:“op\_msg”,“durationMillis”:0}}  
{“t”:{“$date”:“2023-12-06T12:00:44.398+00:00”},“s”:“D2”, “c”:“QUERY”, “id”:22783, “ctx”:“conn296204”,“msg”:“Received interrupt request for unknown op”,“attr”:{“opId”:833802,“kno  
wnOps”:}}  
{“t”:{“$date”:“2023-12-06T12:00:44.398+00:00”},“s”:“D1”, “c”:“ASSERT”, “id”:23074, “ctx”:“conn296204”,“msg”:“User assertion”,“attr”:{“error”:“HostUnreachable: Connection closed b  
y peer”,“file”:“src/mongo/transport/service\_state\_machine.cpp”,“line”:299}}  
{“t”:{“$date”:“2023-12-06T12:00:44.398+00:00”},“s”:“D1”, “c”:“ASSERT”, “id”:23074, “ctx”:“conn296204”,“msg”:“User assertion”,“attr”:{“error”:“HostUnreachable: Connection closed b  
y peer”,“file”:“src/mongo/transport/service\_state\_machine.cpp”,“line”:444}}  
{“t”:{“$date”:“2023-12-06T12:00:44.398+00:00”},“s”:“I”, “c”:“NETWORK”, “id”:22944, “ctx”:“conn296204”,“msg”:“Connection ended”,“attr”:{“remote”:“127.0.0.1:50974”,“uuid”:“a8bdc188  
-28fa-4c74-8a5f-fd256c947af5”,“connectionId”:296204,“connectionCount”:3}}  
{“t”:{“$date”:“2023-12-06T12:00:44.982+00:00”},“s”:“D1”, “c”:“-”, “id”:4333221, “ctx”:“ReplicaSetMonitor-TaskExecutor”,“msg”:“RSM received successful hello”,“attr”:{“host”:“my  
-cluster-name-rs0-1.my-cluster-name-rs0.psmdb-operator.svc.cluster.local:27017”,“replicaSet”:“rs0”,“helloReply”:{“topologyVersion”:{“processId”:{“$oid”:“656f254402f345c3da28a89f”},“c  
ounter”:6},“hosts”:[“my-cluster-name-rs0-0.my-cluster-name-rs0.psmdb-operator.svc.cluster.local:27017”,“my-cluster-name-rs0-1.my-cluster-name-rs0.psmdb-operator.svc.cluster.local:270  
17”,“my-cluster-name-rs0-2.my-cluster-name-rs0.psmdb-operator.svc.cluster.local:27017”],“setName”:“rs0”,“setVersion”:8,“isWritablePrimary”:true,“secondary”:false,“primary”:“my-cluste  
r-name-rs0-1.my-cluster-name-rs0.psmdb-operator.svc.cluster.local:27017”,“tags”:{“podName”:“my-cluster-name-rs0-1”,“serviceName”:“my-cluster-name”},“me”:“my-cluster-name-rs0-1.my-clu  
ster-name-rs0.psmdb-operator.svc.cluster.local:27017”,“electionId”:{“$oid”:“7fffffff0000000000000034”},“lastWrite”:{“opTime”:{“ts”:{“$timestamp”:{“t”:1701864038,“i”:7}},“t”:52},“last  
WriteDate”:{“$date”:“2023-12-06T12:00:38.000Z”},“majorityOpTime”:{“ts”:{“$timestamp”:{“t”:1701864038,“i”:7}},“t”:52},“majorityWriteDate”:{“$date”:“2023-12-06T12:00:38.000Z”}},“isImpl  
icitDefaultMajorityWC”:true,“maxBsonObjectSize”:16777216,“maxMessageSizeBytes”:48000000,“maxWriteBatchSize”:100000,“localTime”:{“$date”:“2023-12-06T12:00:44.981Z”},“logicalSessionTim  
eoutMinutes”:30,“connectionId”:127,“minWireVersion”:17,“maxWireVersion”:17,“readOnly”:false,“compression”:[“snappy”,“zstd”,“zlib”],“ok”:1,“lastCommittedOpTime”:{“$timestamp”:{“t”:170  
1864038,“i”:7}},“$clusterTime”:{“clusterTime”:{“$timestamp”:{“t”:1701864043,“i”:1}},“signature”:{“hash”:{“$binary”:{“base64”:“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”,“subType”:“0”}},“keyId”:0}  
},“$configTime”:{“$timestamp”:{“t”:1701864043,“i”:1}},“$topologyTime”:{“$timestamp”:{“t”:1701090629,“i”:6}},“operationTime”:{“$timestamp”:{“t”:1701864038,“i”:7}}}}}  
{“t”:{“$date”:“2023-12-06T12:00:45.308+00:00”},“s”:“I”, “c”:“NETWORK”, “id”:22943, “ctx”:“listener”,“msg”:“Connection accepted”,“attr”:{“remote”:“127.0.0.1:51012”,“uuid”:“bae4b4f  
1-88d6-40f7-abd6-8ac7051e9c41”,“connectionId”:296207,“connectionCount”:4}}

## Additional Information:

Attached the yaml file

 ![Screenshot 2023-12-06 at 5.54.10 PM](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/5/543ca952273c8a234613b88f2a484705bcf5bf6a.png)

---

<div class="post-metadata">

**Author:** ![Parag\_Bhayani](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/parag_bhayani/32/3710_2.png) [@Parag\_Bhayani](https://forums.percona.com/u/Parag_Bhayani)\
**Post date:** [December 6, 2023, 2:46pm UTC](https://forums.percona.com/t/sharding-not-enabled-for-db-2shards-3-configserv-3-mongos/26983/2 "2023-12-06T14:46:46Z")

</div>

Hi @preetsb86,

Welcome to Percona Community!!

From the above mentioned error " **sharding not enabled for db shardemo1**" it suggest that the database has been not enabled for sharding yet, which means that “sh.enableSharding(“shardemo1”)” did not went through. Also in the script you did not run “use shardemo1” to go inside the database and that should be the first step.

When you enable sharding on Database level, then run rs.status command and verify the “partitioned” parameter for that particular database and it should be set to “true”.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/a/a309032f91ecf92f089c60c56d6ad2dfe3f4a5d3.png)

Regards,

---

<div class="post-metadata">

**Author:** ![preetsb86](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@preetsb86](https://forums.percona.com/u/preetsb86)\
**Post date:** [December 7, 2023, 8:13am UTC](https://forums.percona.com/t/sharding-not-enabled-for-db-2shards-3-configserv-3-mongos/26983/3 "2023-12-07T08:13:47Z")

</div>

Thanks for the quick response Parag. I have executed the command “use shademo1” , forgotten to mention in the above description.  
{ “\_id” : “shardemo1”, “primary” : “rs1”, **“partitioned” : false** , “version” : { “uuid” : UUID(“c6cf9469-b73d-4b1d-8a56-8937f4dc87fa”), “timestamp” : Timestamp  
(1701847144, 1), “lastMod” : 1 } }  
The output of the enablesharding is ok , while enabling ahrding on collection getting the sharding is not enabled and partion also shows as “false”  
pasting the yaml file , Can you please help if there are any configuration need to be enabled…Thanks in advance  
mongos\> sh.enableSharding(“shardemo1”)  
{  
“ok” : 1,  
“$clusterTime” : {  
“clusterTime” : Timestamp(1701935634, 5),  
“signature” : {  
“hash” : BinData(0,“ZKXNfQJErQBF1LZdnTO2DUhRnqY=”),  
“keyId” : NumberLong(“7304143901814685721”)  
}  
},  
“operationTime” : Timestamp(1701935634, 5)  
}

---

<div class="post-metadata">

**Author:** ![preetsb86](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@preetsb86](https://forums.percona.com/u/preetsb86)\
**Post date:** [December 13, 2023, 4:32pm UTC](https://forums.percona.com/t/sharding-not-enabled-for-db-2shards-3-configserv-3-mongos/26983/4 "2023-12-13T16:32:10Z")

</div>

**“partitioned” : false** … Please let me know how to enable the parttioned as “true”
