Reading the documentation of MongoDB about how to configure a master-slave configuration of a cluster (our cluster will have more than 12 nodes, so unfortunately we can't have a replica-set configuration), how can I promote a slave to master without having to stop any process?

Is there any command we can use, like the slaveof command of Redis which allows us to promote a slave to master without the need to restart the process?

This is what we found on MongoDB documentation (http://docs.mongodb.org/manual/core/master-slave/):

To permanently failover from a unavailable or damaged master (A in the following example) to a slave (B):

Shut down A. Stop mongod on B. Back up and move all data files that begin with local on B from the dbpath. Warning Removing local.* is irrevocable and cannot be undone. Perform this step with extreme caution. Restart mongod on B with the --master option. Note This is a one time operation, and is not reversible. A cannot become a slave of B until it completes a full resync.

Is this really the only way?


An addendum to sysadmins answer to clear up your question in the comments:

No, currently (as of 2.4) there is no way to go beyond 12 nodes in a replica set. You could look into using the Mongo Connector to have multiple sets though as a possible solution. The connector allows you to replay the ops from one set in another set, essentially by tailing the oplog (which is how replication works in general). However, that would mean that resolving any sync issues between clusters would not be automatic and would essentially be up to you.

For reference, the relevant issue to vote/watch to increase the 12 node limit is SERVER-3110 - it is currently slated for 2.5.x (the current unstable development branch), but as with all such things until it is committed and in a stable release, you cannot say for sure when it will be done.


Yes, this is indeed the method for switching a role. There is a reason why Master/Slave is deprecated in favor of replica-sets. In the Master/Slave documentation they give a method to emulate Master/Slave behavior using Replica Sets and two nodes. If you set things up that way, you can get a hot-swap of mode through a simple command from the Mongo console.

{ _id : 'replSet', members : [ { _id : 0, host : "mongomaster", priority : 0},
                               { _id : 1, host : "mongoslave", priority : 1 } ]

That would provide you with a role-swap. You're telling the replica set to swap which servers are acting as Primary and which as Secondary.

  • In this master-slave mode emulated by replica-sets can I overcome the limitation of the 12 nodes? I mean, can I have more than 12 nodes this way? – Kico Lobo Jul 24 '13 at 18:59
  • @KicoLobo I do not know. – sysadmin1138 Jul 24 '13 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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