Repository class for MongoDB Make db operations easier across the services

Type Parameters

Constructors

Properties

collectionName: string

collection name

db: Db

mongodb database instance

logger: undefined | Logger = undefined

logger instance

Methods

  • Aggregate records

    Parameters

    • pipeline: Document[]

      aggregation pipeline

    Returns Promise<Document[]>

    aggregated result

  • Count the non softDeleted records in the collection

    Returns Promise<number>

    number of records in the collection with delFlg = 0

  • Count the records in the collection by condition

    Parameters

    • query: Filter<T>

      filter

    • Optional search: SearchAggregatorType

      search condition (only for atlas hosted mongodb full text search)

    Returns Promise<number>

    number of records

  • Create a new record of entity

    Parameters

    • entity: T

      object to create

    Returns Promise<{
        id: string;
    }>

    id of the created object

  • Create list of record

    Parameters

    • entities: T[]

      objects to create

    Returns Promise<{
        id: string;
    }[]>

    id list

  • Delete one record from database

    Parameters

    • id: string

      id of object to delete

    Returns Promise<boolean>

    true if deleted successfully or false if not

  • Delete by condition

    Parameters

    • query: Filter<T>

      condition to delete

    Returns Promise<number>

    number of records deleted

  • Find records by query

    Parameters

    • query: Filter<T>

    Returns Promise<WithId<T>[]>

    list of queries objects

  • Find one record by id If no record is found, return null

    Parameters

    • id: string

      id of object to find

    Returns Promise<null | WithId<T>>

    Object or null

  • Find one record by query, If multiple records are found, return the first one If no record is found, return null

    Parameters

    • query: Filter<T>

    Returns Promise<null | WithId<T>>

    Object or null

  • Restore a softDeleted record

    Parameters

    • id: string

      id of object to restore

    Returns Promise<boolean>

    true if restored successfully or false if not

  • softDelete a record from database mark the delFlg to be 1

    Parameters

    • id: string

      id of object to softDelete

    Returns Promise<boolean>

    true if deleted successfully or false if not

  • softDelete by condition

    Parameters

    • query: Filter<T>

      condition to delete

    Returns Promise<number>

    number of records deleted

  • Update a record by id

    Parameters

    • id: string

      id of object to update

    • partialObject: DeepPartial<T>

      data to update

    Returns Promise<{
        id: string;
    }>

    id of the updated object

  • Update records by query

    Parameters

    • query: Filter<T>

      condition

    • updateQuery: UpdateFilter<T>

      update query

    Returns Promise<number>

    number of records been updated

Generated using TypeDoc