Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Mongo<T>

The mongo instance constructor

Type parameters

Hierarchy

  • Mongo

Index

Constructors

constructor

Properties

Readonly client

client: MongoClient

The mongo client used

Readonly collection

collection: Collection<Document<T>>

The collection instance used

Readonly db

db: Db

The database instance used

Methods

all

  • all(session?: ClientSession): Promise<Cursor<T>>
  • Get all document in the collection

    Parameters

    • Optional session: ClientSession

      Session of transaction, if any

    Returns Promise<Cursor<T>>

delete

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

    Parameters

    • key: string

      The document key

    • Optional session: ClientSession

      Session of transaction, if any

    Returns Promise<DeleteResult>

deleteAll

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

    Parameters

    • Optional session: ClientSession

      Session of transaction, if any

    Returns Promise<DeleteResult>

filter

get

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

    Parameters

    • key: string

      The document key

    • Optional session: ClientSession

      Session of transaction, if any

    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, session?: ClientSession): Promise<Cursor<T>>
  • Find and match all document key with the matcher in the collection

    Parameters

    • matcher: RegExp

      The matcher in regex

    • Optional session: ClientSession

      Session of transaction, if any

    Returns Promise<Cursor<T>>

query

  • query(match: Match<T>, session?: ClientSession): Query<T>
  • Create a query object

    Parameters

    • match: Match<T>
    • Optional session: ClientSession

    Returns Query<T>

set

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

    Parameters

    • key: string

      The data key

    • value: T

      The data value

    • Optional session: ClientSession

      Session of transaction, if any

    Returns Promise<UpdateResult>

Generated using TypeDoc