startSession

On this page本页内容

Definition定义

startSession

The startSession command starts a new logical session for a sequence of operations.startSession命令为一系列操作启动新的逻辑会话

startSession has the following syntax:具有以下语法:

{ startSession: 1 }

To run startSession, use the db.runCommand( { <command> } ) method.要运行startSession,请使用db.runCommand( { <command> } )方法。

db.runCommand( { startSession: 1 } )
Important重要

featureCompatibilityVersion must be 3.6 or greater to use the startSession command.必须为3.6或更高才能使用startSession命令。

Tip提示
See also: 参阅:

Behavior行为

If the deployment enforces authentication/authorization, you must be authenticated to run the startSession command. 如果部署强制执行身份验证/授权,则必须对您进行身份验证才能运行startSession命令。The user who runs startSession owns the created session, and only that user can use the session.运行startSession的用户拥有创建的会话,只有该用户才能使用该会话。

If the deployment does not enforce authentication/authorization, a created session has no owner and can be used by any user on any connection. 如果部署未强制执行身份验证/授权,则创建的会话没有所有者,任何用户都可以在任何连接上使用该会话。If the user authenticates and creates a session for a deployment that does not enforce authentication/authorization, the user owns the session. 如果用户验证并为未强制验证/授权的部署创建会话,则用户拥有该会话。However, any user on any connection may use the session.但是,任何连接上的任何用户都可以使用会话。

If the deployment transitions to auth without any downtime, any sessions without an owner cannot be used.如果部署在没有停机的情况下过渡到身份验证,则无法使用没有所有者的任何会话。

Output输出

In addition to the status and operation time of the command, the startSession returns the following session specific information:除了命令的状态和操作时间外,startSession还返回以下特定于会话的信息:

Field字段Type类型Description描述
idDocument

The document that contains the 16-byte Universally Unique Identifier (UUID) portion of the session's identifier.包含会话标识符的16字节通用唯一标识符(UUID)部分的文档。

id: { id: <UUID> }

The session's identifier consists of this UUID concatenated with the hash of the authenticated user credentials.会话的标识符由这个UUID和经过身份验证的用户凭据的散列组成。

timeoutMinutesnumber

The amount of time, in minutes, since the last client use that a session remains active before expiring. 自上次客户端使用以来,会话在过期前保持活动状态的时间(以分钟为单位)。By default, sessions have an expiration timeout of 30 minutes. 默认情况下,会话的过期超时为30分钟。To change the value, set the localLogicalSessionTimeoutMinutes parameter when starting up mongod. 要更改该值,请在启动mongod时设置localLogicalSessionTimeoutMinutes参数。For replica sets and sharded clusters, you must specify the same value on every member.对于副本集和分片集群,必须为每个成员指定相同的值。

←  refreshSessionsAdministration Commands →