On this page本页内容
dropConnections
New in version 4.2.在版本4.2中新增。
The dropConnections
command drops the mongod
/mongos
instance's outgoing connections to the specified hosts. dropConnections
命令将mongod
/mongos
实例的传出连接丢弃到指定主机。The dropConnections
must be run against the admin
database.dropConnections
必须针对admin
数据库运行。
The command has following syntax:该命令具有以下语法:
db.adminCommand({ dropConnections: 1, hostAndPort : [ "host1:port1", "host2:port2", ... ], comment: <any> })
The command requires the following field:该命令需要以下字段:
hostAndPort | array | |
comment | any |
|
If the deployment enforces authentication/authorization, the 如果部署强制执行身份验证/授权,则dropConnections
command requires the dropConnections
action on the cluster resource.dropConnections
命令需要对群集资源执行dropConnections
s操作。
Create a user-defined role in the 在admin
database where the privilege
array includes the following document:admin
数据库中创建用户定义的角色,其中privilege
数组包含以下文档:
{ "resource" : { "cluster" : true } }, "actions" : [ "dropConnections" ] }
Use 使用db.createUser()
to create a user on the admin
database with the custom role.db.createUser()
在admin
数据库上创建具有自定义角色的用户。
or或
db.grantRolesToUser()
to grant the role to an existing user on the admin
database.db.grantRolesToUser()
将角色授予admin
数据库上的现有用户。For example, the following operation creates a user-defined role on the 例如,以下操作在admin
database with the privileges to support dropConnections
:admin
数据库上创建用户定义的角色,该角色具有支持dropConnections
的权限:
db.getSiblingDB("admin").createRole( { "role" : "dropConnectionsRole", "privileges" : [ { "resource" : { "cluster" : true }, "actions" : [ "dropConnections" ] } ], "roles" : [] } )
Assign the custom role to a user on the 将自定义角色分配给admin
database:admin
数据库上的用户:
db.getSiblingDB("admin").createUser( { "user" : "dropConnectionsUser", "pwd" : "replaceThisWithASecurePassword", "roles" : [ "dropConnectionsRole" ] } )
The created user can execute 创建的用户可以执行dropConnections
.dropConnections
。
For more examples of user creation, see Create a User. 有关创建用户的更多示例,请参阅创建用户。For a tutorial on adding privileges to an existing database user, see Modify Access for an Existing User.有关向现有数据库用户添加权限的教程,请参阅修改现有用户的访问权限。
dropConnections
silently ignores 默认忽略不同时包含远程计算机的主机名和端口的hostAndPort
elements that do not include both the hostname and port of the remote machine.hostAndPort
元素。
Consider a replica set with a recently removed member at 考虑一个副本集,该副本集最近删除了oldhost.example.com:27017
. 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
:dropConnections
命令可确保没有剩余的到oldhost.example.com:27017
的传出连接:
db.adminCommand( { "dropConnections" : 1, "hostAndPort" : [ "oldhost.example.com:27017" ] } )
The command returns output similar to the following:该命令返回类似于以下内容的输出:
{ "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1551375968, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }, "operationTime" : Timestamp(1551375968, 1) }
You can confirm the status of the connection pool for the 您可以使用mongod
or mongos
using the connPoolStats
command.connPoolStats
命令确认mongod
或mongos
的连接池的状态。