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 &
mongod --replSet rs0 --dbpath /data/srd/rs1 --logpath /data/srd/rs1/log.rs1 --port 27001 --fork --logappend --smallfiles --oplogSize 50 &
mongod --replSet rs0 --dbpath /data/srd/rs2 --logpath /data/srd/rs2/log.rs2 --port 27002 --fork --logappend --smallfiles --oplogSize 50 &

For Shards:

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

For Config server:

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

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> sh.enableSharding("test");
        "code" : 193,
        "ok" : 0,
        "errmsg" : "Cannot accept sharding commands if not started with --shardsvr"

2 Answers 2


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


In my case I had no space left in my partition /var/log.

Use df -h to check free space in your partitions and delete the bigger logs.

  • You didn't have to start your replica sets with --shardsvr - you just had to clear some log space? Want to be sure you were actually experiencing the exact same error....
    – RDFozz
    Nov 20, 2017 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.