killAllSessions

On this page本页内容

Definition定义

killAllSessions

The killAllSessions command kills all sessions for the specified users. killAllSessions命令将终止指定用户的所有会话。[1]

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.runCommand( { killAllSessions: [ { user: <user>, db: <dbname> }, ... ]  } )

The command takes an array of documents where each document specifies the user and the user's authentication database. 该命令接受一组文档,其中每个文档指定用户和用户的身份验证数据库。Specify an empty array to kill all sessions for all users in the system. 指定一个空数组以终止系统中所有用户的所有会话。[1]

To view existing sessions, see $listSessions operation or $listLocalSessions.要查看现有会话,请参阅$listSessions操作或$listLocalSessions

Tip提示
See also: 参阅:
[1](1, 2) The killAllSessions operation ignores sessions that have transactions in prepared state. killAllSessions操作忽略事务处于准备状态的会话。See Behavior for details.有关详细信息,请参阅行为

Access Control访问控制

If the deployment enforces authentication/authorization, you must have the killAnySession to run the killAllSessions command.如果部署强制执行身份验证/授权,则必须使用killAnySession运行killAllSessions命令。

Note注意

Users can kill their own sessions even without killAnySession privilege action.即使没有 killAnySession权限操作,用户也可以终止自己的会话。

Behavior行为

In-progress Operations正在进行的操作

Killing a session kills any in-progress operations in the session and closes any open cursors associated with these operations.终止会话将终止会话中正在进行的任何操作,并关闭与这些操作关联的所有打开的游标。

Killed Session Availability已终止会话可用性

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.要查看现有会话,请参阅$listSessions操作或$listLocalSessions

Sessions with Transactions in Prepared State事务处于准备状态的会话

The killAllSessions operation ignores sessions that have transactions in prepared state. killAllSessions操作忽略事务处于准备状态的会话。Transactions in prepared state refer to transactions with write operations that span multiple shards whose commit coordinator has completed the "sendingPrepare" action.处于已准备状态的事务是指具有写操作的事务,这些操作跨越多个分片,提交协调器已完成"sendingPrepare" action操作。

Examples示例

Kill All Sessions终止所有会话

The following operation kills all sessions for all users in the system:以下操作将终止系统中所有用户的所有会话:

db.runCommand( { killAllSessions: [ ] } )

Kill All Sessions for Specific Users终止特定用户的所有会话

The following operation kills all sessions for the user appReader in the db1 and the user reportWriter in db2 databases:以下操作将终止`中用户appReaderdb2数据库中用户reportWriter的所有会话:

db.runCommand( { killAllSessions: [
   { user: "appReader", db: "db1" },
   { user: "reportWriter", db: "db2" }
] } )
←  endSessionskillAllSessionsByPattern →