定义
killSessionskillSessions命令会终止指定的会话。如果已启用访问权限控制,则该命令仅终止用户拥有的会话。 []1
语法
该命令具有以下语法:
db.runCommand( { killSessions: [ { id : <UUID> }, ... ] } )
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
M0 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
命令字段
该命令接受一个文档数组,这些文档指定会话 ID 的 UUID 部分。 指定空数组[ ]可终止所有会话,或者,如果启用了访问控制,则终止用户拥有的所有会话。 [1]
查看现有会话
要查看现有会话,请参阅$listSessions操作或$listLocalSessions 。
| [1] | (1 ,2 ) killSessions操作会忽略事务处于准备状态的会话。有关详细信息,请参阅行为。 |
行为
会话识别
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.
进行中的操作
终止会话会终止会话中所有进行中的操作,并关闭与这些操作关联的所有打开的游标。
终止会话可用性
被终止的会话可能仍会列为当前会话,并且将来的操作可能会使用被终止的会话。 要查看现有会话,请参阅$listSessions操作或$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.
例子
以下操作会终止用户的指定会话:
db.runCommand( { killSessions: [ { id: UUID("f9b3d8d9-9496-4fff-868f-04a6196fc58a") } ] } )
提示