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

killAllSessionsByPattern(数据库命令)

killAllSessionsByPattern

The killAllSessionsByPattern command 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.

该命令接受指定要匹配模式的文档数组:

模式
说明

{ lsid: { id : <UUID> } }

指定要终止的会话 ID 的 UUID 部分。

{ uid: <BinData> }

指定要终止的会话所有者的哈希值。

{ 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]

要查看现有会话,请参阅$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权限操作,用户也可以终止自己的会话。

以下操作会终止所有会话:

db.runCommand( { killAllSessionsByPattern: [ ] } )

以下操作会终止具有指定uid且所有者具有指定角色的所有会话:

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