定義
dropConnectionsThe
dropConnectionscommand drops themongod/mongosinstance's outgoing connections to the specified hosts. ThedropConnectionsmust be run against theadmindatabase.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
コマンドの構文は次のとおりです。
db.adminCommand( { dropConnections: 1, hostAndPort : [ "host1:port1", "host2:port2", ... ], comment: <any> } )
コマンドフィールド
コマンドには次のフィールドが必要です。
フィールド | タイプ | 説明 |
|---|---|---|
| 配列 | 各配列要素は、リモート マシンのホスト名とポートを表します。 |
| any | 任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。
コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。 |
アクセス制御
If the deployment enforces authentication/authorization, the dropConnections command requires the dropConnections action on the cluster resource.
privilege配列に次のドキュメントが含まれるadminデータベースにユーザー定義ロールを作成します。
{ "resource" : { "cluster" : true } }, "actions" : [ "dropConnections" ] }
db.createUser()を使用して、adminデータベースにカスタムロールを持つユーザーを作成します。or
db.grantRolesToUser()を使用して、adminデータベース上の既存のユーザーにロールを付与します。
For example, the following operation creates a user-defined role on the admin database with the privileges to support dropConnections:
db.getSiblingDB("admin").createRole( { "role" : "dropConnectionsRole", "privileges" : [ { "resource" : { "cluster" : true }, "actions" : [ "dropConnections" ] } ], "roles" : [] } )
以下のように、 adminデータベースのユーザーにカスタムロールを割り当てます。
db.getSiblingDB("admin").createUser( { "user" : "dropConnectionsUser", "pwd" : "replaceThisWithASecurePassword", "roles" : [ "dropConnectionsRole" ] } )
The created user can execute dropConnections.
ユーザー作成のその他の例については、「自己管理型配置でのユーザーの作成 」を参照してください。 既存のデータベースユーザーへの特権の追加に関するチュートリアルについては、「既存ユーザーのアクセス権の変更 」を参照してください。
動作
dropConnections silently ignores hostAndPort elements that do not include both the hostname and port of the remote machine.
例
Consider a replica set with a recently removed member at oldhost.example.com:27017. Running the following dropConnections command against each active replica set member ensures there are no remaining outgoing connections to oldhost.example.com:27017:
db.adminCommand( { "dropConnections" : 1, "hostAndPort" : [ "oldhost.example.com:27017" ] } )
このコマンドは、次のような出力を返します。
{ "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1551375968, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : Long(0) } }, "operationTime" : Timestamp(1551375968, 1) }
コマンドを使用して、mongod またはmongos connPoolStatsの接続プールのステータスを確認できます。