Skip to main content
Version: Next

MongoDriver

Database driver for MongoDB.

Hierarchy

Index

Constructors

constructor

Properties

[EntityManagerType]

[EntityManagerType]: MongoEntityManager<MongoDriver>

readonlyinheritedconfig

Methods

aggregate

  • aggregate(entityName, pipeline, ctx): Promise<any[]>
  • Executes a MongoDB aggregation pipeline (MongoDB driver only).


    Parameters

    • entityName: EntityName
    • pipeline: any[]
    • optionalctx: ClientSession

    Returns Promise<any[]>

inheritedclose

  • close(force): Promise<void>
  • Closes the primary connection and all read replicas.


    Parameters

    • optionalforce: boolean

    Returns Promise<void>

inheritedconnect

  • Opens the primary connection and all read replicas.


    Parameters

    • optionaloptions: { skipOnConnect?: boolean }
      • optionalskipOnConnect: boolean

    Returns Promise<MongoConnection>

inheritedconvertException

  • Converts native db errors to standardized driver exceptions


    Parameters

    • exception: Error

    Returns DriverException

count

  • count<T>(entityName, where, options): Promise<number>
  • Counts entities matching the given condition.


    Parameters

    Returns Promise<number>

inheritedcountVirtual

  • countVirtual<T>(entityName, where, options): Promise<number>

createEntityManager

  • Creates a new EntityManager instance bound to this driver.


    Parameters

    • optionaluseContext: boolean

    Returns MongoEntityManager<MongoDriver>

find

  • find<T, P, F, E>(entityName, where, options): Promise<EntityData<T>[]>

findOne

  • findOne<T, P, F, E>(entityName, where, options): Promise<null | EntityData<T>>

findVirtual

  • findVirtual<T>(entityName, where, options): Promise<EntityData<T>[]>
  • Finds entities backed by a virtual (expression-based) definition.


    Parameters

    Returns Promise<EntityData<T>[]>

inheritedgetConnection

  • Returns the write connection or a random read replica.


    Parameters

    Returns MongoConnection

inheritedgetDependencies

  • getDependencies(): string[]
  • Returns the names of native database dependencies required by this driver.


    Returns string[]

inheritedgetMetadata

  • Returns the metadata storage used by this driver.


    Returns MetadataStorage

getORMClass

getPlatform

  • Returns the database platform abstraction for this driver.


    Returns MongoPlatform

inheritedloadFromPivotTable

  • loadFromPivotTable<T, O>(prop, owners, where, orderBy, ctx, options, pivotJoin): Promise<Dictionary<T[]>>
  • When driver uses pivot tables for M:N, this method will load identifiers for given collections from them


    Parameters

    • prop: EntityProperty<any, any>
    • owners: (O extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<O<O>, typeof PrimaryKeyProp> : PK extends keyof O<O> ? ReadonlyPrimary<UnwrapPrimary<O<O>[PK<PK>]>> : PK extends keyof O<O>[] ? ReadonlyPrimary<PrimaryPropToType<O<O>, PK<PK>>> : PK : O extends { _id?: PK } ? string | ReadonlyPrimary<PK> : O extends { id?: PK } ? ReadonlyPrimary<PK> : O extends { uuid?: PK } ? ReadonlyPrimary<PK> : O)[][]
    • optionalwhere: any
    • optionalorderBy: OrderDefinition<T>
    • optionalctx: any
    • optionaloptions: FindOptions<T, any, any, any>
    • optionalpivotJoin: boolean

    Returns Promise<Dictionary<T[]>>

inheritedlockPessimistic

  • lockPessimistic<T>(entity, options): Promise<void>
  • Acquires a pessimistic lock on the given entity.


    Parameters

    Returns Promise<void>

inheritedmapResult

  • mapResult<T>(result, meta, populate): null | EntityData<T>

nativeDelete

  • nativeDelete<T>(entityName, where, options): Promise<QueryResult<T>>
  • Deletes rows matching the given condition.


    Parameters

    • entityName: EntityName<T>
    • where: FilterQuery<T>
    • options: { ctx?: ClientSession } = {}
      • optionalctx: ClientSession

    Returns Promise<QueryResult<T>>

nativeInsert

  • nativeInsert<T>(entityName, data, options): Promise<QueryResult<T>>

nativeInsertMany

  • nativeInsertMany<T>(entityName, data, options): Promise<QueryResult<T>>

nativeUpdate

  • nativeUpdate<T>(entityName, where, data, options): Promise<QueryResult<T>>

nativeUpdateMany

  • nativeUpdateMany<T>(entityName, where, data, options): Promise<QueryResult<T>>

inheritedreconnect

  • Closes all connections and re-establishes them.


    Parameters

    • optionaloptions: { skipOnConnect?: boolean }
      • optionalskipOnConnect: boolean

    Returns Promise<MongoConnection>

inheritedsetMetadata

  • setMetadata(metadata): void
  • Sets the metadata storage and initializes the comparator for all connections.


    Parameters

    Returns void

stream

  • stream<T>(entityName, where, options): AsyncIterableIterator<T, any, any>
  • Returns an async iterator that streams query results one entity at a time.


    Parameters

    Returns AsyncIterableIterator<T, any, any>

streamAggregate

  • streamAggregate<T>(entityName, pipeline, ctx): AsyncIterableIterator<T, any, any>
  • Parameters

    • entityName: EntityName<T>
    • pipeline: any[]
    • optionalctx: ClientSession

    Returns AsyncIterableIterator<T, any, any>

streamVirtual

  • streamVirtual<T>(entityName, where, options): AsyncIterableIterator<EntityData<T>, any, any>

inheritedsyncCollections

  • syncCollections<T, O>(collections, options): Promise<void>
  • Persists changes to M:N collections (inserts/deletes pivot table rows).


    Parameters

    Returns Promise<void>