Search code examples
mongodbconfigshardingreplicaset

How to replace node in sharded replica set?


I got sharded mongodb setup with two replica sets:

mongos> db.runCommand( { listShards : 1 } )
{
    "shards" : [
        {
            "_id" : "rs01",
            "host" : "rs01/10.133.250.140:27017,10.133.250.154:27017"
        },
        {
            "_id" : "rs02",
            "host" : "rs02/10.133.242.7:27017,10.133.242.8:27017"
        }
    ],
    "ok" : 1
}

Node 10.133.250.140 just went down, and I replaced it with another one (ip-address changed). Replica set reconfiguration was pretty easy, just rs.remove() and rs.add() Now I have to update host config for shard rs01. What is proper way to do it?


Solution

  • Many times you would need to modify the host string for a shard. The simplest way to change host string is to run an update operation.

    Connect to mongos and do this -

    > use config
    > db.shards.update({ "_id" : "rs01"},{$set : { "host" : "rs01/newip:27017,anothernewip:27017"} })
    

    You might need to restart all mongos.

    Hope this helps :-)