Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Transaction<T>

A wrapper of mongo class for transaction

Type parameters

Hierarchy

  • Transaction

Index

Constructors

constructor

Properties

Readonly mongo

mongo: Mongo<T>

The mongo instance to wrap

Accessors

session

  • get session(): ClientSession

Methods

all

delete

  • delete(key: string): Promise<DeleteResult>
  • Delete a document from the collection

    Parameters

    • key: string

      The document key

    Returns Promise<DeleteResult>

deleteAll

  • deleteAll(): Promise<DeleteResult>
  • Delete all document in the collection

    Returns Promise<DeleteResult>

filter

get

  • get(key: string): Promise<null | Doc<T>>
  • Get a document from the collection

    Parameters

    • key: string

      The document key

    Returns Promise<null | Doc<T>>

index

  • index(indexSpec: { data?: IndexDirection | { [ K in string | number | symbol]: IndexDirection }; key?: IndexDirection }, options?: CreateIndexesOptions): Promise<void>
  • Create an index in the ocllection

    Parameters

    • indexSpec: { data?: IndexDirection | { [ K in string | number | symbol]: IndexDirection }; key?: IndexDirection }
      • Optional data?: IndexDirection | { [ K in string | number | symbol]: IndexDirection }
      • Optional key?: IndexDirection
    • Optional options: CreateIndexesOptions

    Returns Promise<void>

match

  • match(matcher: RegExp): Promise<Cursor<T>>
  • Find and match all document key with the matcher in the collection

    Parameters

    • matcher: RegExp

      The matcher in regex

    Returns Promise<Cursor<T>>

query

set

  • set(key: string, value: T): Promise<UpdateResult>
  • Set a data into the collection

    Parameters

    • key: string

      The data key

    • value: T

      The data value

    Returns Promise<UpdateResult>

Static abortTransaction

  • abortTransaction(client: MongoClient): Promise<void>
  • Abort transaction for a mongo client

    Parameters

    • client: MongoClient

    Returns Promise<void>

Static commitTransaction

  • commitTransaction(client: MongoClient): Promise<void>
  • Commit transaction for a mongo client

    Parameters

    • client: MongoClient

    Returns Promise<void>

Static startTransaction

  • startTransaction(client: MongoClient, options?: TransactionOptions): Promise<void>
  • Start transaction for a mongo client

    Parameters

    • client: MongoClient
    • Optional options: TransactionOptions

    Returns Promise<void>

Generated using TypeDoc