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

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

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”.

Regards,

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)
}

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