Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

killSessions

On this page

  • Definition
  • Syntax
  • Compatibility
  • Command Fields
  • View Existing Sessions
  • Behavior
  • Example
killSessions

The killSessions command kills the specified sessions. If access control is enabled, the command only kills the sessions owned by the user. [1]

The command has the following syntax:

db.runCommand(
{
killSessions: [ { id : <UUID> }, ... ]
}
)

This command is available in deployments hosted in the following environments:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

Note

This command is not supported in M0, M2, and M5 clusters. For more information, see Unsupported Commands.

The command takes an array of documents that specify the UUID portion of the session id. Specify an empty array [ ] to kill all sessions, or if access control is enabled, all sessions owned by the user. [1]

To view existing sessions, see $listSessions operation or $listLocalSessions.

[1](1, 2) The killSessions operation ignores sessions that have transactions in prepared state. See Behavior for details.

MongoDB concatenates each of the specified UUIDs with the hash of the authenticated user credentials to identify the user's sessions to kill. If the user has no session that match, the killSessions has no effect.

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 killSessions 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.

The following operation kills the specified session for the user:

db.runCommand( { killSessions: [ { id: UUID("f9b3d8d9-9496-4fff-868f-04a6196fc58a") } ] } )

Tip

See also:

←  killAllSessionsByPatternrefreshSessions →