startSession
Definition
New in version 3.6.
The startSession
command starts a new logicalsession for a sequence of operations.
startSession
has the following syntax:
- { startSession: 1 }
To run startSession
, use the db.runCommand( { <command> } )
method.
- db.runCommand( { startSession: 1 } )
Important
featureCompatibilityVersion
must be 3.6 or greater to use thestartSession
command.
See also
Behavior
If the deployment enforces authentication/authorization, you must beauthenticated to run the startSession
command. The userwho runs startSession
owns the created session, and onlythat user can use the session.
If the deployment does not enforce authentication/authorization, acreated session has no owner and can be used by any user on anyconnection. If the user authenticates and creates a session for adeployment that does not enforce authentication/authorization, the userowns the session. However, any user on any connection may use thesession.
If the deployment transitions to auth without any downtime, anysessions without an owner cannot be used.
Output
In addition to the status and operation time of the command, thestartSession
returns the following session specificinformation:
Field | Type | Description |
---|---|---|
id | Document | The document that contains the 16-byte Universally UniqueIdentifier (UUID) portion of the session’s identifier.The session’s identifier consists of this UUID concatenated withthe hash of the authenticated user credentials. |
timeoutMinutes | number | The amount of time, in minutes, since the last client use that asession remains active before expiring. By default, sessionshave an expiration timeout of 30 minutes. To change the value,set the localLogicalSessionTimeoutMinutes parameterwhen starting up mongod . For replica sets and shardedclusters, you must specify the same value on every member. |