killAllSessionsByPattern

On this page本页内容

Definition定义

killAllSessionsByPattern

The killAllSessionsByPattern command kills all sessions that match any of the specified patterns. killAllSessionsByPattern命令将杀死与任何指定模式匹配的所有会话。[1]

Syntax语法

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

db.runCommand( { killAllSessionsByPattern: [ <pattern>, ... ] } )

The command takes an array of documents that specify the patterns to match:该命令获取指定要匹配的模式的文档数组:

PatternDescription描述
{ lsid: { id : <UUID> } }Specify the UUID portion of the session id to kill.指定要终止的会话id的UUID部分。
{ uid: <BinData> }Specifies the hash of the owner of the sessions to kill.指定要终止的会话的所有者的哈希。
{ users: [ { user: <user>, db: <dbname> }, ... ] }Specifies the owners of the sessions to kill. Requires additional privileges. 指定要终止的会话的所有者。需要其他权限。See Access Control. 请参阅访问控制
{ roles: [ { role: <role>, db: <dbname> }, ... ] }Specifies the roles assigned to the owners of the sessions to kill. 指定分配给要终止的会话所有者的角色。Requires additional privileges. 需要其他权限。See Access Control. 请参阅访问控制

Specify an empty array to kill all sessions. 指定一个空数组以终止所有会话。[1]

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

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

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

Access Control访问控制

If the deployment enforces authentication/authorization, you must have the killAnySession privilege action to run the killAllSessionsByPattern command.如果部署强制执行身份验证/授权,则必须具有killAnySession权限操作才能运行killAllSessionsByPattern命令。

For patterns that include users or roles, you must also have privileges that grant impersonate action on the cluster resource.对于包含usersroles的模式,您还必须具有在群集资源上授予模拟操作的权限。

Note注意

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

Examples示例

Kill All Sessions终止所有会话

The following operation kills all sessions:以下操作将终止所有会话:

db.runCommand( { killAllSessionsByPattern: [ ] } )

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

The following operation kills all sessions that have the specified uid and whose owner has the specified role:以下操作将终止具有指定uid且其所有者具有指定角色的所有会话:

db.runCommand( { killAllSessionsByPattern: [
   { "uid" : BinData(0,"oBRA45vMY78p1tv6kChjQPTdYsnCHi/kA/fFMZTIV1o=") },
   { roles: [ { role: "readWrite", db: "test" } ] }
] } )
←  killAllSessionskillSessions →