killAllSessionsByPattern (original) (raw)
killAllSessionsByPattern
The killAllSessionsByPattern command kills all sessions that match any of the specified patterns. [1]
The command has the following syntax:
db.runCommand(
{
killAllSessionsByPattern: [ <pattern>, ... ]
}
)
This command is available in deployments hosted in the following environments:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
Important
This command is not supported in M0, M2, M5, and Flex clusters. For more information, see Unsupported Commands.
- MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
- MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
The command takes an array of documents that specify the patterns to match:
Pattern | Description |
---|---|
{ lsid: { id : } } | Specify the UUID portion of the session ID to kill. |
{ uid: } | Specifies the hash of the owner of the sessions to kill. |
{ users: [ { user: , db: }, ... ] } | Specifies the owners of the sessions to kill. Requires additional privileges. SeeAccess Control. |
{ roles: [ { role: , db: }, ... ] } | Specifies the roles assigned to the owners of the sessions to kill. Requires additional privileges. SeeAccess Control. |
Specify an empty array to kill all sessions. [1]
To view existing sessions, see $listSessions operation or$listLocalSessions.
See also:
Killing a session kills any in-progress operations in the session and closes any open cursors associated with these operations.
The killed session may still be listed as a current session, and future operations may use the killed session. To view existing sessions, see$listSessions operation or $listLocalSessions.
The killAllSessionsByPattern operation ignores sessions that have Transactions in prepared state. Transactions in prepared state refer to transactions with write operations that span multiple shards whose commit coordinator has completed the "sendingPrepare" action.
If the deployment enforces authentication/authorization, you must have the killAnySession privilege action to run thekillAllSessionsByPattern command.
For patterns that include users
or roles
, you must also have privileges that grant impersonate action on the cluster resource.
Note
Users can kill their own sessions even without thekillAnySession privilege action.
The following operation kills all sessions:
db.runCommand( { killAllSessionsByPattern: [ ] } )
The following operation kills all sessions that have the specifieduid
and whose owner has the specified role:
db.runCommand( { killAllSessionsByPattern: [
{ "uid" : BinData(0,"oBRA45vMY78p1tv6kChjQPTdYsnCHi/kA/fFMZTIV1o=") },
{ roles: [ { role: "readWrite", db: "test" } ] }
] } )