- Reference >
- Database Commands >
- Administration Commands >
- dropConnections
dropConnections¶
On this page
-
dropConnections¶ New in version 4.2.
The
dropConnectionscommand drops themongod/mongosinstance’s outgoing connections to the specified hosts. ThedropConnectionsmust be run against theadmindatabase.The command has following syntax:
The command requires the following field:
Field Type Description hostAndPortarray Each array element represents the hostname and port of a remote machine. commentany Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:
- mongod log messages, in the
attr.command.cursor.commentfield. - Database profiler output, in the
command.commentfield. currentOpoutput, in thecommand.commentfield.
A comment can be any valid BSON type (string, integer, object, array, etc).
New in version 4.4.
- mongod log messages, in the
Access Control¶
If the deployment enforces
authentication/authorization,
the dropConnections command requires the
dropConnections action on the
cluster resource.
Create a user-defined role in the admin
database where the privilege array includes the following document:
Use
db.createUser()to create a user on theadmindatabase with the custom role.or
Use
db.grantRolesToUser()to grant the role to an existing user on theadmindatabase.
For example, the following operation creates a
user-defined role on the admin database with the privileges
to support dropConnections:
Assign the custom role to a user on the admin database:
The created user can execute dropConnections.
For more examples of user creation, see Add Users. For a tutorial on adding privileges to an existing database user, see Modify Access for an Existing User.
Behavior¶
dropConnections silently ignores hostAndPort elements
that do not include both the hostname and port of the remote machine.
Example¶
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:
The command returns output similar to the following:
You can confirm the status of the connection pool for the
mongod or mongos using the
connPoolStats command.