Sharding state has not been initialized with a shardIdentity document


I’ve an issue with my replica shared cluster.
“Cannot accept sharding commands if sharding state has not been initialized with a shardIdentity document”.

The created db is going to mongoshard_rs1.

The shard is added on my mongos :

How could I initilized the sharded cluster ? Every created DB on this clusted should be sharded.

Thanks for your help :slight_smile:

Hi @Jerome_Heritier and welcome to the community forum!!

To understand the issue in a better way, could you help with a few details for the above deployment and error you are seeing.

  1. Could you help me with the steps to reproduce the above issue or what steps did you follow and ended up with the above error?
  2. What is the MongoDB version for the sharding deployment? Please include the version of all mongod and mongos processes.
  3. Is this an old or a fresh deployment ?

If this is a restored data from another deployment, I would suggest you to follow the documentation to restore a sharded cluster and let us know if you have any further questions.

Best Regards

Hi @Aasawari thanks for your answer and sorry for the late reply.

I finally find a solution by adding a shardIdentity document on the first replicaset (mongoshard-rs1n1) of mongoshard_rs1 group. It was missing on the admin default db of mongoshard-rs1n1.

    "_id" : "shardIdentity",
    "clusterId" : ObjectId("clusterId"),
    "shardName" : "mongoshard_rs1",
    "configsvrConnectionString" : "mongoshard_cfg_rs1/mongoshard-cfg1n1:27017,mongoshard-cfg1n2:27017,mongoshard-cfg1n3:27017"