Mongoose.prototype.startSession()

Parameters
  • [options] «Object» see the mongodb driver options

  • [options.causalConsistency=true] «Boolean» set to false to disable causal consistency

  • [callback] «Function»

Returns:
  • «Promise<ClientSession>» promise that resolves to a MongoDB driver ClientSession

Requires MongoDB >= 3.6.0. Starts a MongoDB session for benefits like causal consistency, retryable writes, and transactions.

Calling mongoose.startSession() is equivalent to calling mongoose.connection.startSession(). Sessions are scoped to a connection, so calling mongoose.startSession() starts a session on the default mongoose connection.