startSession

Definition

  • startSession

New in version 3.6.

The startSession command starts a new logicalsession for a sequence of operations.

startSession has the following syntax:

  1. { startSession: 1 }

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

  1. db.runCommand( { startSession: 1 } )

Important

featureCompatibilityVersion must be 3.6 or greater to use thestartSession command.

See also

Mongo.startSession()

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:

FieldTypeDescription
idDocumentThe document that contains the 16-byte Universally UniqueIdentifier (UUID) portion of the session’s identifier.
  1. id: { id: <UUID> }
The session’s identifier consists of this UUID concatenated withthe hash of the authenticated user credentials.
timeoutMinutesnumberThe 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.