Remove Members from Replica Set
To remove a member of a replica set use either of the following procedures.
rs.remove()in either of the following forms to remove the member:
MongoDB may disconnect the shell briefly if the replica set needs to elect a new primary. The shell then automatically reconnects in such cases. The shell may display a
DBClientCursor::init call() failederror even though the command succeeds.
To remove a member you can manually edit the replica set configuration document, as described here.
rs.conf()method to view the current configuration document and determine the position in the
membersarray of the member to remove:
mongod_C.example.netis in position
2of the following configuration file:
Assign the current configuration document to the variable
cfgobject to remove the member.
Overwrite the replica set configuration document with the new configuration by issuing the following:
To confirm the new configuration, issue
For the example above the output would be: