MongoDB 3.4 Sharding Error. “Cannot accept sharding commands if not started with --shardsvr” I have installed mongoDB 3.4.5 in centOS 7.2 machine. I am configuring sharding in standalone mode.

Steps I followed:

For Replica Sets:

mongod --replSet rs0 --dbpath /data/srd/rs0 --logpath /data/srd/rs0/log.rs0 --port 27000 --fork --logappend --smallfiles --oplogSize 50 &amp;
mongod --replSet rs0 --dbpath /data/srd/rs1 --logpath /data/srd/rs1/log.rs1 --port 27001 --fork --logappend --smallfiles --oplogSize 50 &amp;
mongod --replSet rs0 --dbpath /data/srd/rs2 --logpath /data/srd/rs2/log.rs2 --port 27002 --fork --logappend --smallfiles --oplogSize 50 &amp;


For Shards:

mongod --replSet rs0 --shardsvr --dbpath /data/srd/srd0 --logpath /data/srd/srd0/log.srd0 --port 27020 --fork --logappend --smallfiles --oplogSize 50 &amp;
mongod --replSet rs0 --shardsvr --dbpath /data/srd/srd1 --logpath /data/srd/srd1/log.srd1 --port 27021 --fork --logappend --smallfiles --oplogSize 50 &amp;
mongod --replSet rs0 --shardsvr --dbpath /data/srd/srd2 --logpath /data/srd/srd2/log.srd2 --port 27022 --fork --logappend --smallfiles --oplogSize 50 &amp;


For Config server:

mongod --configsvr --replSet configReplSet --dbpath /data/srd/cfgrep0 --logpath /data/srd/cfgrep0/log.cfgrep0 --port 27006 --fork &amp;
mongod --configsvr --replSet configReplSet --dbpath /data/srd/cfgrep1 --logpath /data/srd/cfgrep1/log.cfgrep1 --port 27007 --fork &amp;
mongod --configsvr --replSet configReplSet --dbpath /data/srd/cfgrep2 --logpath /data/srd/cfgrep2/log.cfgrep2 --port 27008 --fork &amp;


To start Mongos:

mongos --configdb configReplSet/sit:27006,sit:27007,sit:27008 --port 26060


I am able to login the mongos shell and also able to add the shards. But while enabling the shard I am getting exceptions as below.

mongos&gt; sh.enableSharding("test");
{
        "code" : 193,
        "ok" : 0,
        "errmsg" : "Cannot accept sharding commands if not started with --shardsvr"
}
First.. You cannot have two same name replica sets in one cluster (rs0), rename that second one to rs1. (Ports 27020 - 270122).

Error message is telling directly what you should do.. So, add --shardsvr to every started replica set. 

From mongod --replSet xxx  to  mongod --shardsvr --replSet xxx

And of course after log in to mongoS service, you need to add those (two) replica sets to your cluster 

sh.addShard("rs0/address1:27000, address2:27001, address3:27002")

And that other rs1 too..