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

startSession(数据库命令)

startSession

The startSession command starts a new logical session for a sequence of operations.

提示

In mongosh, this command can also be run through the Mongo.startSession() helper method.

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

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

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

该命令具有以下语法:

db.runCommand(
{
startSession: 1
}
)

To run startSession, use the db.runCommand( { <command> } ) method.

db.runCommand(
{
startSession: 1
}
)

重要

featureCompatibilityVersion must be 3.6 or greater to use the startSession command.

If the deployment enforces authentication/authorization, you must be authenticated to run the startSession command. The user who runs startSession owns the created session, and only that user can use the session.

如果部署不强制执行身份验证/授权,则创建的会话没有所有者,任何用户可以在任何连接上使用该会话。 如果用户对不强制执行身份验证/授权的部署进行身份验证并创建会话,则用户拥有该会话。 但是,任何连接上的任何用户都可以使用该会话。

如果部署在没有停机的情况下过渡到身份验证,则无法使用任何没有所有者的会话。

会话只能与创建会话的 MongoClient 对象一起使用。单个会话不能同时使用。使用单个会话的操作必须按顺序运行。

In addition to the status and operation time of the command, the startSession returns the following session specific information:

字段
类型
说明

id

文档

包含会话标识符的 16 字节通用唯一标识符 (UUID) 部分的文档。

id: { id: <UUID> }

会话标识符由该 UUID 与经过身份验证的用户档案的哈希值连接组成。

timeoutMinutes

数字

自客户端上次使用以来会话在过期之前保持活动状态的时间量(以分钟为单位)。 默认情况下,会话的超时时间为 30 分钟。 要更改该值,请在启动localLogicalSessionTimeoutMinutes 时设置mongod 参数。对于副本集和分片集群,您必须为每个成员指定相同的值。

给本页内容打分