This version of the documentation is archived and no longer supported.

Convert a Master-Slave Deployment to a Replica Set


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.


To convert a master-slave deployment to a replica set, restart the current master as a one-member replica set.

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


    This should return a document that resembles the following:

       "ismaster" : true,
       "msg" : "isdbgrid",
       "maxBsonObjectSize" : 16777216,
       "maxMessageSizeBytes" : 48000000,
       "maxWriteBatchSize" : 100000,
       "localTime" : ISODate("2017-11-15T17:50:05.775Z"),
       "logicalSessionTimeoutMinutes" : 30,
       "maxWireVersion" : 6,
       "minWireVersion" : 0,
       "ok" : 1,
       "$clusterTime" : {
          "clusterTime" : Timestamp(1510768200, 1),
          "signature" : {
             "hash" : BinData(0,"VKMQp+F/p+nDZldmWTUzBz7A8Kc="),
             "keyId" : NumberLong("6488693018630029321")
       "operationTime" : Timestamp(1510768200, 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( { _id: "<setname>", members: [ { _id: 0, host: "<host:port>" } ] } )

    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.