定义
killAllSessionsByPatternThe
killAllSessionsByPatterncommand kills all sessions that match any of the specified patterns. [1]
语法
该命令具有以下语法:
db.runCommand( { killAllSessionsByPattern: [ <pattern>, ... ] } )
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
重要
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
命令字段
该命令接受指定要匹配模式的文档数组:
模式 | 说明 |
|---|---|
| 指定要终止的会话 ID 的 UUID 部分。 |
| 指定要终止的会话所有者的哈希值。 |
| Specifies the owners of the sessions to kill. Requires additional privileges. See Access Control. |
| 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]
要查看现有会话,请参阅$listSessions操作或$listLocalSessions 。
| [1] | (1, 2) The killAllSessionsByPattern operation ignores sessions that have transactions in prepared state. See Behavior for details. |
行为
进行中的操作
终止会话会终止会话中所有进行中的操作,并关闭与这些操作关联的所有打开的游标。
终止会话可用性
被终止的会话可能仍会列为当前会话,并且将来的操作可能会使用被终止的会话。 要查看现有会话,请参阅$listSessions操作或$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 the killAllSessionsByPattern command.
对于包含users或roles的模式,您还必须具有授予对集群资源执行impersonate操作的权限。
注意
即使没有killAnySession权限操作,用户也可以终止自己的会话。
示例
killAllSessions
以下操作会终止所有会话:
db.runCommand( { killAllSessionsByPattern: [ ] } )
终止特定用户的所有会话
以下操作会终止具有指定uid且所有者具有指定角色的所有会话:
db.runCommand( { killAllSessionsByPattern: [ { "uid" : BinData(0,"oBRA45vMY78p1tv6kChjQPTdYsnCHi/kA/fFMZTIV1o=") }, { roles: [ { role: "readWrite", db: "test" } ] } ] } )