- Replication >
- Replication Reference >
- Convert a Master-Slave Deployment to a Replica Set
Convert a Master-Slave Deployment to a Replica Set¶
Removed
MongoDB 4.0 removes support for master-slave replication. Before you can upgrade to MongoDB 4.0, if your deployment uses master-slave replication, you must upgrade to a replica set.
To convert your master-slave replication, see Convert a Master-Slave Deployment to a Replica Set.
Procedure¶
To convert a master-slave deployment to a replica set, restart the current master as a one-member replica set.
To confirm that the current instance is master, run:
This should return a document that resembles the following:
Shut down the
mongod
processes on the master and all slave(s), using the following command while connected to each instance:Back up your
/data/db
directories, in case you need to revert to the master-slave deployment.Start the former master with the
--replSet
option, as in the following:Connect to the
mongod
with themongo
shell, and initiate the replica set with the following command: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:
To add the former slaves as secondaries to the replica set, remove the their data directories and add to the replica set. See Add Members to a Replica Set to add new members to a replica set.