Options
All
  • Public
  • Public/Protected
  • All
Menu

A class representing a client session on the server

NOTE: not meant to be instantiated directly.

Hierarchy

Index

Constructors

Methods

  • Ends this session on the server

    Returns Promise<void>

  • deprecated

    Callbacks are deprecated and will be removed in the next major version. See mongodb-legacy for migration assistance

    Parameters

    Returns Promise<void>

  • deprecated

    Callbacks are deprecated and will be removed in the next major version. See mongodb-legacy for migration assistance

    Parameters

    Returns void

  • deprecated

    Callbacks are deprecated and will be removed in the next major version. See mongodb-legacy for migration assistance

    Parameters

    Returns void

  • advanceOperationTime(operationTime: Timestamp): void
  • Advances the operationTime for a ClientSession.

    Parameters

    • operationTime: Timestamp

      the BSON.Timestamp of the operation type it is desired to advance to

    Returns void

  • Advances the clusterTime for a ClientSession to the provided clusterTime of another ClientSession

    Parameters

    • clusterTime: ClusterTime

      the $clusterTime returned by the server from another session in the form of a document containing the BSON.Timestamp clusterTime and signature

    Returns void

  • Used to determine if this session equals another

    Parameters

    Returns boolean

  • incrementTransactionNumber(): void
  • Increment the transaction number on the internal ServerSession

    privateremarks

    This helper increments a value stored on the client session that will be added to the serverSession's txnNumber upon applying it to a command. This is because the serverSession is lazily acquired after a connection is obtained

    Returns void

  • inTransaction(): boolean
  • Returns boolean

    whether this session is currently in a transaction or not

  • Starts a new transaction with the given options.

    Parameters

    Returns void

  • Commits the currently active transaction in this session.

    Returns Promise<<internal>.Document>

  • deprecated

    Callbacks are deprecated and will be removed in the next major version. See mongodb-legacy for migration assistance

    Parameters

    Returns void

  • Aborts the currently active transaction in this session.

    Returns Promise<<internal>.Document>

  • deprecated

    Callbacks are deprecated and will be removed in the next major version. See mongodb-legacy for migration assistance

    Parameters

    Returns void

  • toBSON(): never
  • This is here to ensure that ClientSession is never serialized to BSON.

    Returns never

  • Runs a provided callback within a transaction, retrying either the commitTransaction operation or entire transaction as needed (and when the error permits) to better ensure that the transaction can complete successfully.

    IMPORTANT: This method requires the user to return a Promise, and await all operations. Any callbacks that do not return a Promise will result in undefined behavior.

    remarks

    This function:

    • Will return the command response from the final commitTransaction if every operation is successful (can be used as a truthy object)
    • Will return undefined if the transaction is explicitly aborted with await session.abortTransaction()
    • Will throw if one of the operations throws or throw statement is used inside the withTransaction callback

    Checkout a descriptive example here:

    see

    https://www.mongodb.com/developer/quickstart/node-transactions/

    Type Parameters

    • T = void

    Parameters

    Returns Promise<<internal>.Document>

    A raw command response or undefined

  • removeAllListeners<EventKey>(event?: string | symbol | EventKey): ClientSession
  • listenerCount<EventKey>(type: string | symbol | EventKey): number
  • Type Parameters

    • EventKey extends "ended"

    Parameters

    • type: string | symbol | EventKey

    Returns number

  • eventNames(): string[]
  • getMaxListeners(): number

Properties

errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

captureRejectionSymbol: typeof captureRejectionSymbol
captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

defaultMaxListeners: number
hasEnded: boolean
clientOptions?: <internal>.MongoOptions
supports: { causalConsistency: boolean }

Type declaration

  • causalConsistency: boolean
clusterTime?: ClusterTime
operationTime?: Timestamp
explicit: boolean
defaultTransactionOptions: TransactionOptions
transaction: Transaction

Accessors

  • The server id associated with this session

    Returns ServerSessionId

  • Returns ServerSession

  • get snapshotEnabled(): boolean
  • Whether or not this session is configured for snapshot reads

    Returns boolean

  • get loadBalanced(): boolean
  • Returns boolean

  • get isPinned(): boolean
  • Returns boolean

Generated using TypeDoc