对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

killAllSessions(数据库命令)

killAllSessions

The killAllSessions command kills all sessions for the specified users. [1]

该命令具有以下语法:

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

此命令可用于以下环境中托管的部署:

重要

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.

以下操作将终止系统中所有用户的所有会话:

db.runCommand( { killAllSessions: [ ] } )

以下操作将终止 db1 数据库中用户 appReader 和 db2 数据库中用户 reportWriter 的所有会话:

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