0

I have added a shard to an existing cluster, and when I do db.printShardingStatus() I see a distribution:

mongos> db.printShardingStatus()
--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5c84149e75f51a74e9796add")
  }
  shards:
        {  "_id" : "shard0000",  "host" : "127.0.0.1:27023",  "state" : 1 }
        {  "_id" : "shard0001",  "host" : "127.0.0.1:27024",  "state" : 1 }
        {  "_id" : "shard0002",  "host" : "localhost:27025",  "state" : 1 }
  active mongoses:
        "4.0.6" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  3
        Last reported error:  Error connecting to localhost:27025 (127.0.0.1:27025) :: caused by :: Connection refused
        Time of Reported error:  Sat Mar 09 2019 20:55:55 GMT+0000 (UTC)
        Migration Results for the last 24 hours: 
                8 : Success
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shard0000   1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0) 
        {  "_id" : "testdb",  "primary" : "shard0001",  "partitioned" : true,  "version" : {  "uuid" : UUID("68b7f8fe-17f6-4049-87ce-6c616c7746b7"),  "lastMod" : 1 } }
                testdb.testcollection
                        shard key: { "testkey" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shard0000   3
                                shard0001   3
                                shard0002   1
                        { "testkey" : { "$minKey" : 1 } } -->> { "testkey" : "key0" } on : shard0002 Timestamp(9, 0) 
                        { "testkey" : "key0" } -->> { "testkey" : "key20968" } on : shard0000 Timestamp(7, 1) 
                        { "testkey" : "key20968" } -->> { "testkey" : "key4265" } on : shard0000 Timestamp(4, 0) 
                        { "testkey" : "key4265" } -->> { "testkey" : "key53621" } on : shard0000 Timestamp(6, 0) 
                        { "testkey" : "key53621" } -->> { "testkey" : "key64595" } on : shard0001 Timestamp(5, 1) 
                        { "testkey" : "key64595" } -->> { "testkey" : "key8552" } on : shard0001 Timestamp(9, 1) 
                        { "testkey" : "key8552" } -->> { "testkey" : { "$maxKey" : 1 } } on : shard0001 Timestamp(4, 1) 

But when I access the newly added shard (shard0002), the collection is empty? Does anyone know why?

4
  • Adding a shard to a cluster creates an imbalance, since the new shard has no chunks. While MongoDB begins migrating data to the new shard immediately, it can take some time before the cluster balances. Are you still with same status?
    – Mani
    Mar 10, 2019 at 1:31
  • @tomdinh, What is the MongoDB version(x,y,z)? Mar 10, 2019 at 4:35
  • @tomdinh, At existing shard, how many nodes is there? Mar 10, 2019 at 4:41
  • 1
    I solved it. had to wait for a while for rebalancing
    – tom dinh
    Mar 11, 2019 at 3:55

1 Answer 1

0

Add Shards to a Cluster

As mentioned in MongoDB documentation,

Adding a shard to a cluster creates an imbalance since the new shard has no chunks. While MongoDB begins migrating data to the new shard immediately, it can take some time before the cluster balances.

Your Answer

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

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