Skip to main content
Version: 5.9

MongoDriver

Hierarchy

  • DatabaseDriver<MongoConnection>
    • MongoDriver

Index

Constructors

constructor

  • new MongoDriver(config: Configuration<IDatabaseDriver<Connection>>): MongoDriver
  • Parameters

    • config: Configuration<IDatabaseDriver<Connection>>

    Returns MongoDriver

Properties

[EntityManagerType]

[EntityManagerType]: MongoEntityManager<MongoDriver>

readonlyconfig

config: Configuration<IDatabaseDriver<Connection>>

Methods

aggregate

  • aggregate(entityName: string, pipeline: any[], ctx?: ClientSession): Promise<any[]>
  • Parameters

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

    Returns Promise<any[]>

close

  • close(force?: boolean): Promise<void>
  • Parameters

    • optionalforce: boolean

    Returns Promise<void>

connect

  • connect(): Promise<MongoConnection>
  • Returns Promise<MongoConnection>

convertException

  • convertException(exception: Error): DriverException
  • Converts native db errors to standardized driver exceptions


    Parameters

    • exception: Error

    Returns DriverException

count

  • count<T>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T, never>, ctx?: ClientSession): Promise<number>
  • Type parameters

    • T: object

    Parameters

    • entityName: string
    • where: FilterQuery<T>
    • options: CountOptions<T, never> = {}
    • optionalctx: ClientSession

    Returns Promise<number>

countVirtual

  • countVirtual<T>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>
  • Type parameters

    • T: object

    Parameters

    • entityName: string
    • where: FilterQuery<T>
    • options: CountOptions<T, any>

    Returns Promise<number>

createCollections

  • createCollections(): Promise<void>
  • @deprecated

    use orm.getSchemaGenerator().createSchema() instead


    Returns Promise<void>

createEntityManager

  • createEntityManager<D>(useContext?: boolean): D[typeof EntityManagerType]
  • Type parameters

    • D: IDatabaseDriver<Connection, D> = IDatabaseDriver<Connection>

    Parameters

    • optionaluseContext: boolean

    Returns D[typeof EntityManagerType]

dropCollections

  • dropCollections(): Promise<void>
  • @deprecated

    use orm.getSchemaGenerator().dropSchema() instead


    Returns Promise<void>

ensureIndexes

  • ensureIndexes(): Promise<void>
  • @deprecated

    use orm.getSchemaGenerator().ensureIndexes() instead


    Returns Promise<void>

find

  • find<T, P>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P>): Promise<EntityData<T>[]>
  • Finds selection of entities


    Type parameters

    • T: object
    • P: string = never

    Parameters

    • entityName: string
    • where: FilterQuery<T>
    • options: FindOptions<T, P> = {}

    Returns Promise<EntityData<T>[]>

findOne

  • findOne<T, P>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P>): Promise<null | EntityData<T>>
  • Finds single entity (table row, document)


    Type parameters

    • T: object
    • P: string = never

    Parameters

    • entityName: string
    • where: FilterQuery<T>
    • options: FindOneOptions<T, P> = ...

    Returns Promise<null | EntityData<T>>

findVirtual

  • findVirtual<T>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any>): Promise<EntityData<T>[]>
  • Type parameters

    • T: object

    Parameters

    • entityName: string
    • where: FilterQuery<T>
    • options: FindOptions<T, any>

    Returns Promise<EntityData<T>[]>

getConnection

  • getConnection(type?: ConnectionType): MongoConnection
  • Parameters

    • type: ConnectionType = 'write'

    Returns MongoConnection

getDependencies

  • getDependencies(): string[]
  • Returns name of the underlying database dependencies (e.g. mongodb or mysql2) for SQL drivers it also returns knex in the array as connectors are not used directly there


    Returns string[]

getMetadata

  • getMetadata(): MetadataStorage
  • Returns MetadataStorage

getPlatform

  • getPlatform(): MongoPlatform
  • Returns MongoPlatform

init

  • init(): Promise<void>
  • Returns Promise<void>

loadFromPivotTable

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


    Type parameters

    • T: object
    • O: object

    Parameters

    • prop: EntityProperty<any>
    • owners: Primary<O>[][]
    • optionalwhere: FilterQuery<any>
    • optionalorderBy: QueryOrderMap<T>[]
    • optionalctx: any
    • optionaloptions: FindOptions<T, any>

    Returns Promise<Dictionary<T[]>>

lockPessimistic

  • lockPessimistic<T>(entity: T, options: LockOptions): Promise<void>
  • Type parameters

    • T

    Parameters

    • entity: T
    • options: LockOptions

    Returns Promise<void>

mapResult

  • mapResult<T>(result: EntityDictionary<T>, meta?: EntityMetadata<T>, populate?: PopulateOptions<T>[]): null | EntityData<T>
  • Type parameters

    • T: object

    Parameters

    • result: EntityDictionary<T>
    • optionalmeta: EntityMetadata<T>
    • populate: PopulateOptions<T>[] = []

    Returns null | EntityData<T>

nativeDelete

  • nativeDelete<T>(entityName: string, where: FilterQuery<T>, options?: { ctx?: ClientSession }): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

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

    Returns Promise<QueryResult<T>>

nativeInsert

  • nativeInsert<T>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • entityName: string
    • data: EntityDictionary<T>
    • options: NativeInsertUpdateOptions<T> = {}

    Returns Promise<QueryResult<T>>

nativeInsertMany

  • nativeInsertMany<T>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • entityName: string
    • data: EntityDictionary<T>[]
    • options: NativeInsertUpdateManyOptions<T> = {}

    Returns Promise<QueryResult<T>>

nativeUpdate

  • nativeUpdate<T>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • entityName: string
    • where: FilterQuery<T>
    • data: EntityDictionary<T>
    • options: NativeInsertUpdateOptions<T> & UpsertOptions<T> = {}

    Returns Promise<QueryResult<T>>

nativeUpdateMany

  • nativeUpdateMany<T>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • entityName: string
    • where: FilterQuery<T>[]
    • data: EntityDictionary<T>[]
    • options: NativeInsertUpdateOptions<T> & UpsertManyOptions<T> = {}

    Returns Promise<QueryResult<T>>

reconnect

  • reconnect(): Promise<MongoConnection>
  • Returns Promise<MongoConnection>

refreshCollections

  • refreshCollections(options?: CreateSchemaOptions): Promise<void>
  • @deprecated

    use orm.getSchemaGenerator().refreshDatabase() instead


    Parameters

    • options: CreateSchemaOptions = {}

    Returns Promise<void>

setMetadata

  • setMetadata(metadata: MetadataStorage): void
  • Parameters

    • metadata: MetadataStorage

    Returns void

syncCollection

  • syncCollection<T, O>(coll: Collection<T, O>, options?: DriverMethodOptions): Promise<void>
  • Type parameters

    • T: object
    • O: object

    Parameters

    • coll: Collection<T, O>
    • optionaloptions: DriverMethodOptions

    Returns Promise<void>