rs.remove()

On this page本页内容

Definition定义

rs.remove(hostname)

Removes the member described by the hostname parameter from the current replica set. 从当前副本集中删除hostname参数描述的成员。This function will disconnect the shell briefly and forces a reconnection as the replica set renegotiates which member will be primary. 此函数将短暂断开shell连接,并在副本集重新协商哪个成员将是primary时强制重新连接。As a result, the shell will display an error even if this command succeeds.因此,即使此命令成功,shell也会显示错误。

The rs.remove() method has the following parameter:rs.remove()方法具有以下参数:

Parameter参数Type类型Description描述
hostnamestringThe hostname of a system in the replica set.副本集中系统的主机名。
Note注意

Before running the rs.remove() operation, it is good practice to shut down the replica set member that you are removing.在运行rs.remove()操作之前,最好关闭要删除的副本集成员。

Behavior行为

By default, replica set members wait for 5 minutes before dropping connections to the removed member. 默认情况下,副本集成员会等待5分钟,然后再断开与已删除成员的连接。In sharded replica sets, you can modify this timeout using the ShardingTaskExecutorPoolHostTimeoutMS server parameter.在分片副本集中,可以使用ShardingTaskExecutorPoolHostTimeoutMS服务器参数修改此超时。

New in version 4.2.在版本4.2中新增 To immediately drop all outgoing connections from the replica set to the removed member, run the dropConnections administrative command on each remaining member on the replica set:要立即删除从副本集到已删除成员的所有传出连接,请对副本集上的每个剩余成员运行dropConnections管理命令:

db.adminCommand(
  {
    "dropConnections" : 1,
    "hostAndPort" : [
      "<hostname>:<port>"
    ]
  }
)

Replace <hostname> with the hostname of the removed member and <port> with the port the mongod listened on.<hostname>替换为已删除成员的主机名,将<port>替换为mongod侦听的端口。

←  rs.reconfigForPSASet()rs.status() →