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

Remove Members from Replica Set

To remove a member of a replica set use either of the following procedures.

Remove a Member Using rs.remove()

  1. Connect to the replica set’s current primary. To determine the current primary, use db.isMaster() while connected to any member of the replica set.

  2. Use rs.remove() in either of the following forms to remove a member:

    rs.remove("mongod3.example.net:27017")
    rs.remove("mongod3.example.net")
    
  3. Shut down the mongod instance for the member you removed. To shut down the instance, connect using the mongo shell and the db.shutdownServer() method.

Remove a Member Using rs.reconfig()

To remove a member you can manually edit the replica set configuration document, as described here.

  1. Connect to the replica set’s current primary. To determine the current primary, use db.isMaster() while connected to any member of the replica set.

  2. Issue the rs.conf() method to view the current configuration document and determine the position in the members array of the member to remove:

    Example

    mongod_C.example.net is in position 2 of the following configuration file:

    {
        "_id" : "rs",
        "version" : 7,
        "members" : [
            {
                "_id" : 0,
                "host" : "mongod_A.example.net:27017"
            },
            {
                "_id" : 1,
                "host" : "mongod_B.example.net:27017"
            },
            {
                "_id" : 2,
                "host" : "mongod_C.example.net:27017"
            }
        ]
    }
    
  3. Assign the current configuration document to the variable cfg:

    cfg = rs.conf()
    
  4. Modify the cfg object to remove the member.

    Example

    To remove mongod_C.example.net:27017 use the following JavaScript operation:

    cfg.members.splice(2,1)
    
  5. Overwrite the replica set configuration document with the new configuration by issuing the following:

    rs.reconfig(cfg)
    

    As a result of rs.reconfig() the shell may disconnect while the replica set renegotiates which member is primary. The shell displays a DBClientCursor::init call() failed error even though the command succeeds, and will automatically reconnected.

  6. To confirm the new configuration, issue rs.conf().

    For the example above the output would be:

    {
        "_id" : "rs",
        "version" : 8,
        "members" : [
            {
                "_id" : 0,
                "host" : "mongod_A.example.net:27017"
            },
            {
                "_id" : 1,
                "host" : "mongod_B.example.net:27017"
            }
        ]
    }
    
  7. Shut down the mongod instance for the member you removed. To shut down the instance, connect using the mongo shell and the db.shutdownServer() method.