mongodb

Can I change the name of my replica set while mongod processes are running?


If so, how?

When I first created the replica set, I chose a confusing name; I'd like to change it now.

The replica set name is mentioned in /etc/mongod.conf, and I'm not sure when it reads/rereads that. Since the replica set name can also be passed in as a command-line parameter, I'm assuming (and currently testing) the following:

In other words, I'm assuming the answer to my original question is "no, you must restart" or "no, replica set name is immutable". I'll probably figure this out soon enough since I'm trying it locally.


Solution

  • Here's how to do it with downtime:

    1. Stop all the servers
      • If authentication is enabled, make sure it is disabled or changes to the local.system.replset collection may not be authorized.
    2. Start up each server without the --replSet option, pointing at the correct data directory.
    3. Update the local.system.replset doc on each server with the new replica set name. You have to change every server here.
      Here is how to update local.system.replset in mongo shell:

      use local  
      var doc = db.system.replset.findOne()  
      doc._id = 'NewReplicaSetName'
      db.system.replset.save(doc)  
      db.system.replset.remove({_id:'OldReplicaSetName'})
      
    4. Shut them down again.
    5. Change the /etc/mongod.conf replSet option to the new name on all the servers.
    6. Start them all up with the original options.