定義
rs.remove(hostname)hostnameパラメーターで記述されたノードを現在のレプリカセットから削除します。この関数は、shell を一時的に切断し、レプリカセットがどのノードをプライマリにするかを再ネゴシエートするときに再接続を強制します。その結果、このコマンドが成功しても、shell はエラーを表示します。The
rs.remove()method has the following parameter:Parameterタイプ説明hostnamestring
レプリカセット内のシステムのホスト名
注意
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)
Removing a member changes the number of voting members in the replica set, which can change the implicit default write concern.
You must explicitly set the global default write concern before attempting to reconfigure a replica set with a configuration that would change the implicit default write concern. To set the global default write concern, use the setDefaultRWConcern command.
削除により、過半数のノードをレプリカ構成をインストールするまで待機させる
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 がリスニングしていたポートに置き換えます。