定义
killAllSessionsThe
killAllSessionscommand kills all sessions for the specified users. [1]
语法
该命令具有以下语法:
db.runCommand( { killAllSessions: [ { user: <user>, db: <dbname> }, ... ] } )
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
重要
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
命令字段
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]
查看现有会话
要查看现有会话,请参阅$listSessions操作或$listLocalSessions 。
| [1] | (1, 2) The killAllSessions operation ignores sessions that have transactions in prepared state. See Behavior for details. |
访问控制
If the deployment enforces authentication/authorization, you must have the killAnySession to run the killAllSessions command.
注意
即使没有 killAnySession 特权动作,用户也可以终止自己的会话。
行为
进行中的操作
终止会话会终止会话中所有进行中的操作,并关闭与这些操作关联的所有打开的游标。
终止会话可用性
被终止的会话可能仍会列为当前会话,并且将来的操作可能会使用被终止的会话。 要查看现有会话,请参阅$listSessions操作或$listLocalSessions 。
事务处于准备状态的会话
The killAllSessions 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.
示例
killAllSessions
以下操作将终止系统中所有用户的所有会话:
db.runCommand( { killAllSessions: [ ] } )
终止特定用户的所有会话
以下操作将终止 db1 数据库中用户 appReader 和 db2 数据库中用户 reportWriter 的所有会话:
db.runCommand( { killAllSessions: [ { user: "appReader", db: "db1" }, { user: "reportWriter", db: "db2" } ] } )