## Convert a Master-Slave Deployment to a Replica Set 

To convert a master-slave deployment to a replica set, restart the current master as a one-member replica set. Then remove the data directories from previous secondaries and add them as new secondaries to the new replica set. 

1. To confirm that the current instance is master, run: 

db.isMaster() 

This should return a document that resembles the following: 

{ "ismaster" : true, "maxBsonObjectSize" : 16777216, "maxMessageSizeBytes" : 48000000, "localTime" : ISODate("2013-07-08T20:15:13.664Z"), "ok" : 1 } 

2. Shut down the mongod processes on the master and all slave(s), using the following command while connected to each instance: 

db.adminCommand({shutdown : 1, force : true}) 

3. Back up your /data/db directories, in case you need to revert to the master-slave deployment. 

4. Start the former master with the --replSet option, as in the following: 

mongod --replSet <setname> 

5. Connect to the mongod with the mongo shell, and initiate the replica set with the following command: 

rs.initiate() 

When the command returns, you will have successfully deployed a one-member replica set. You can check the status of your replica set at any time by running the following command: 

rs.status() 

You can now follow the convert a standalone to a replica set (page 614) tutorial to deploy your replica set, picking up from the Expand the Replica Set (page 615) section. 

## Failing over to a Slave (Promotion) 

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

1. Shut down A . 

2. Stop mongod on B . 

3. 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. 

4. 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. 

