rs.remove()

Definition

  • rs.remove(hostname)
  • Removes the member described by the hostname parameter from thecurrent replica set. This function will disconnect theshell briefly and forces a reconnection as the replica setrenegotiates which member will be primary. As aresult, the shell will display an error even if this commandsucceeds.

The rs.remove() method has the following parameter:

ParameterTypeDescriptionhostnamestringThe hostname of a system in the replica set.

Note

Before running the rs.remove() operation, it is goodpractice to shut down the replica set member that you areremoving.

Behavior

By default, replica set members wait for 5 minutes before droppingconnections to the removed member. In sharded replica sets, you canmodify this timeout using theShardingTaskExecutorPoolHostTimeoutMS server parameter.

New in version 4.2: To immediately drop all outgoing connections from the replica set tothe removed member, run the dropConnectionsadministrative command on each remaining member on the replica set:

  1. db.adminCommand(
  2. {
  3. "dropConnections" : 1,
  4. "hostAndPort" : [
  5. "<hostname>:<port>"
  6. ]
  7. }
  8. )

Replace <hostname> with the hostname of the removed member and<port> with the port the mongod listened on.