Can I, and if I can, how can I rename a shard in Mongo?
Like if I wanted to change the instances of rs0 to rep0 below:
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 4,
"minCompatibleVersion" : 4,
"currentVersion" : 5,
"clusterId" : ObjectId("111111111111")
}
shards:
{ "_id" : "rs0", "host" : "rs0/mongo0a:27017,mongo0b:27017" }
...
I have thought about removing and re-adding the shard, but I'm not sure how I'd do that without having to drain the shard and drop dbs.
Currently 0 of the collections have sharding enabled, I just have a few standalones added as shards.
Thanks
Best Answer
No, there is no supported way to rename a shard at present, though as you mention you could remove and re-add. Even then it is not as simple as you might think because although you can specify a name when adding a shard, it does not end there - there is the replica set itself to worry about. The name specification when adding is just the value of the
_id
, see the following example (my replica set is rs0, like yours):Note that all that has changed is the
_id
for the shard, the"host"
value remains the same, becausers0
is the name of the replica set - if you try to userep0
there it will fail to add. Hence, all that a remove and re-add will give you is a mismatch between the two names.To change that
host
value, not only do you have to remove/re-add the shard, you also have to alter the replica set config before you re-add the shard. In other words, thereplSet
parameter must be changed to berep0
also, and that means re-initializing the set - not an easy task either.Overall, it is possible to get to where you want, but there will be a large amount of work and it will not be quick (drains, re-init of the set), especially if you have a lot of data. For the sake of changing a couple of strings, I would generally recommend leaving them as-is.