killAllSessions

Definition

  • killAllSessions

New in version 3.6.

The killAllSessions command kills all sessions for thespecified users.

Note

Killing a session kills any in-progress operations in thesession, and closes any open cursors associated with theseoperations. The killed session may still be listed as acurrent session, and future operations may use the killedsession.

  1. { killAllSessions: [ { user: <user>, db: <dbname> }, ... ] }

The command takes an array of documents that specify the user anddatabase name. Specify multiple array entries to kill sessions formultiple users. Specify an empty array to kill all sessions for allusers in the system.

To run killAllSessions, use the db.runCommand( { <command> } ) method.

To view existing sessions, see $listSessions operationor $listLocalSessions.

See also

killAllSessionsByPattern

Access Control

If the deployment enforces authentication/authorization, you must havethe killAnySession to run thekillAllSessions command.

Note

Users can kill their own sessions even withoutkillAnySession privilege action.

Examples

Kill All Sessions

The following operation kills all sessions for all users in the system:

  1. db.runCommand( { killAllSessions: [ ] } )

Kill All Sessions for Specific Users

The following operation kills all sessions for the user appReaderin the db1 and db2 databases:

  1. db.runCommand( { killAllSessions: [ { user: "appReader", db: "db1" }, { user: "appReader", db: "db2" } ] } )