I've got a standalone MongoDB server with a lot amount of data on it. Let's say, it's srv1 server. I've decided to make a sharded cluster, so I've created additional servers srv2 and srv3.

We have:

  • srv1 - existing mongodb server with data, that will be shard0001.
  • srv2 - new mongodb server, that will be shard0000.
  • srv3 - also new mongodb server, that will be config server with running mongos instance. Mongos instance running only on that server.
  • vk - database I want to be sharded.

On srv3 I've started a mongos with --configdb rs0/ option and a mongod with --replSet rs0 --configsvr --dbpath /data/config --port 27002. After that, via the config instance i've added srv1 and srv2 as a shards with sh.addShard("srv1-2:27017") command. Also, on srv2 I've created an empty database and collections with the same names as on srv1. After that on config server i've executed sh.adminCommand({enableSharding: "vk"}); command.

What I have now:

Surprisingly, it's working. When i'm trying to read/write something to my database, using srv3 as connection point, it's working perfectly! When i've did something before (using srv1 standalone), average response time was about 2 seconds, now it's 0.02 seconds.

The problem I have:

Well, the sharding is not working. Database on srv2 is empty. Here is the output of the db.printShardingStatus() command from srv3:

--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5d81f91bdde81f72ac4d1a0a")
        {  "_id" : "shard0000",  "host" : "srv2:27017",  "state" : 1 }
        {  "_id" : "shard0001",  "host" : "srv1:27017",  "state" : 1 }
  active mongoses:
        "3.6.3" : 1
        Currently enabled: yes
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  5
        Last reported error:  Connection refused
        Time of Reported error:  Wed Sep 18 2019 14:41:13 GMT+0200 (CEST)
        Migration Results for the last 24 hours:
                No recent migrations
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                                shard0000       1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
        {  "_id" : "shard0000",  "primary" : "shard0000",  "partitioned" : true }
        {  "_id" : "vk",  "primary" : "shard0001",  "partitioned" : true }
        {  "_id" : "vk:",  "primary" : "shard0000",  "partitioned" : true }

Additional info:

The balancer says Connection refused, but i've opened 27017 and 27002 port on every machine in cluster. It's still not working. In mongos (srv3) log there are a lot of successful connections both to srv1 and srv2. Telnet says the same - everything is fine and opened. I've added shards without --replSet options. Mongod instances on srv1 and srv2 working without that options too. I didn't created any chunk keys or something like this.

Thank you for the reading, will be very grateful for any help.

  • Are you starting mongod of srv1 and srv2 with the option --shardsvr? Sep 19, 2019 at 20:57
  • Yes, sure, both with --shardsvr. Here is the full command for srv1-2 - mongod --bind_ip --shardsvr --port 27017 --fork --logpath /data/logs/mongod.log
    – Mikhail N.
    Sep 20, 2019 at 8:02
  • @MikhailN, What is the MongoDB Version(x,y,z)? Sep 23, 2019 at 4:41
  • My version is 3.6.3
    – Mikhail N.
    Sep 23, 2019 at 8:35

1 Answer 1


About MongoDB 3.6 shards, from the official release notes:

Starting in 3.6, shards must be replica sets.

When you add shards, should be something like:

sh.addShard( "rs1/mongodb3.example.net:27017,mongodb4.example.net:27017,mongodb5.example.net:27017" )

With a status like:

--- Sharding Status ---
sharding version: {
   "_id" : 1,
   "minCompatibleVersion" : 5,
   "currentVersion" : 6,
   "clusterId" : ObjectId("5be0a488039b1964a7208c60")
   {  "_id" : "rs0",  "host" : "rs0/mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017",  "state" : 1 }
   {  "_id" : "rs1",  "host" : "rs1/mongodb3.example.net:27017,mongodb4.example.net:27017,mongodb5.example.net:27017",  "state" : 1 }
active mongoses:
   "3.6.8" : 1
  • Thanks for the reply! Should I delete my current shards and add them again? If i'll delete them from my config server, will my data on the current shard (srv1 in my case) be safe and unmodified?
    – Mikhail N.
    Sep 23, 2019 at 8:34
  • @MikhailN. Yes, removing the old, and placing the replicated ones should work. But as the sharding never took place properly, you can delete the configDB and start anew. Your data was never moved in the first place, I doubt anything could be lost, but always have a backup in place. As the saying goes, better to be safe, than to be sorry. Sep 23, 2019 at 21:51

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.