rs.remove()
On this page本页内容
Definition定义
rs.remove(hostname)-
Removes the member described by the从当前复制副本集中删除由hostnameparameter 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. As a result, the shell will display an error even if this command succeeds.此函数将短暂断开shell的连接,并在副本集重新协商哪个成员将是primary时强制重新连接。因此,即使此命令成功,shell也会显示错误。Thers.remove()method has the following parameter:rs.remove()方法具有以下参数:Parameter参数Type类型Description描述hostnamestring The hostname of a system in the replica set.复制副本集中系统的主机名。NoteBefore 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侦听的端口。