定义
rs.remove(hostname)从当前副本集中删除由
hostname参数描述的成员。此函数将短暂断开 Shell 连接,并在副本集重新协商哪个成员为主节点时强制重新连接。所以即使该命令成功执行,Shell 也会显示错误。The
rs.remove()method has the following parameter:Parameter类型说明hostname字符串
副本集中系统的主机名。
注意
Before running the
rs.remove()operation, it is good practice to shut down the replica set member that you are removing.
兼容性
此方法可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
行为
全局写关注
删除节点会改变副本集中投票节点的数量,这可能会改变 隐式默认写关注(write concern)。
在尝试使用会改变隐式默认写关注(write concern)的 配置 重新配置一个 副本集 之前,您必须显式设置全局默认 写关注(write concern) 。要设置全局默认写关注(write concern),请使用 setDefaultRWConcern 命令。
删除一直等到大多数节点安装副本配置
rs.remove() runs the replSetReconfig command with a configuration that omits the removed member. The method waits until a majority of voting replica set members install the new replica configuration before it returns success. A voting member is any replica set member where members[n].votes is 1, including arbiters. To learn how replica set members install a new configuration, see Reconfiguration Waits Until a Majority of Members Install the Replica Configuration.
rs.remove() does not accept a maxTimeMS limit. If a majority of voting members never install the new configuration, the operation waits indefinitely.
与已删除节点的连接
默认情况下,副本集节点等待 5 分钟,然后再删除到删除的节点的连接。在分片副本集中,您可以使用 ShardingTaskExecutorPoolHostTimeoutMS 服务器参数修改该超时。
要立即删除从副本集到已删除成员的所有传出连接,请对副本集的每个剩余成员运行 dropConnections 管理命令:
db.adminCommand( { "dropConnections" : 1, "hostAndPort" : [ "<hostname>:<port>" ] } )
将 <hostname> 替换为已删除成员的主机名,将 <port> 替换为 mongod 监听的端口。