MongoDriver
Hierarchy
- DatabaseDriver<MongoConnection>
- MongoDriver
Index
Constructors
Properties
Methods
- aggregate
- close
- connect
- convertException
- count
- countVirtual
- createEntityManager
- find
- findOne
- findVirtual
- getConnection
- getDependencies
- getMetadata
- getORMClass
- getPlatform
- loadFromPivotTable
- lockPessimistic
- mapResult
- nativeDelete
- nativeInsert
- nativeInsertMany
- nativeUpdate
- nativeUpdateMany
- reconnect
- setMetadata
- stream
- streamAggregate
- streamVirtual
- syncCollections
Constructors
constructor
Parameters
Returns MongoDriver
Properties
[EntityManagerType]
readonlyinheritedconfig
Methods
aggregate
Executes a MongoDB aggregation pipeline (MongoDB driver only).
Parameters
entityName: EntityName
pipeline: any[]
optionalctx: ClientSession
Returns Promise<any[]>
inheritedclose
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
Counts entities matching the given condition.
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: CountOptions<T, never> = {}
Returns Promise<number>
inheritedcountVirtual
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: CountOptions<T, any>
Returns Promise<number>
createEntityManager
Creates a new EntityManager instance bound to this driver.
Parameters
optionaluseContext: boolean
Returns MongoEntityManager<MongoDriver>
find
Finds selection of entities
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: FindOptions<T, P, F, E> = {}
Returns Promise<EntityData<T>[]>
findOne
Finds single entity (table row, document)
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: FindOneOptions<T, P, F, E> = ...
Returns Promise<null | EntityData<T>>
findVirtual
Finds entities backed by a virtual (expression-based) definition.
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: FindOptions<T, any, any, any>
Returns Promise<EntityData<T>[]>
inheritedgetConnection
Returns the write connection or a random read replica.
Parameters
type: ConnectionType = 'write'
Returns MongoConnection
inheritedgetDependencies
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
Returns Constructor<MongoMikroORM<MongoEntityManager<MongoDriver>, (string | EntitySchema<any, never, EntityCtor<any>> | EntityClass<Partial<any>>)[]>>
getPlatform
Returns the database platform abstraction for this driver.
Returns MongoPlatform
inheritedloadFromPivotTable
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
Acquires a pessimistic lock on the given entity.
Parameters
entity: T
options: LockOptions
Returns Promise<void>
inheritedmapResult
Maps raw database result to entity data, converting column names to property names.
Parameters
result: EntityDictionary<T>
optionalmeta: EntityMetadata<T, EntityCtor<T>>
populate: PopulateOptions<T>[] = []
Returns null | EntityData<T>
nativeDelete
Deletes rows matching the given condition.
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: { ctx?: ClientSession } = {}
optionalctx: ClientSession
Returns Promise<QueryResult<T>>
nativeInsert
Inserts a single row into the database.
Parameters
entityName: EntityName<T>
data: EntityDictionary<T>
options: NativeInsertUpdateOptions<T> = {}
Returns Promise<QueryResult<T>>
nativeInsertMany
Inserts multiple rows into the database in a single batch operation.
Parameters
entityName: EntityName<T>
data: EntityDictionary<T>[]
options: NativeInsertUpdateManyOptions<T> = {}
Returns Promise<QueryResult<T>>
nativeUpdate
Updates rows matching the given condition.
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
data: EntityDictionary<T>
options: NativeInsertUpdateOptions<T> & UpsertOptions<T, never> = {}
Returns Promise<QueryResult<T>>
nativeUpdateMany
Updates multiple rows with different payloads in a single batch operation.
Parameters
entityName: EntityName<T>
where: FilterQuery<T>[]
data: EntityDictionary<T>[]
options: NativeInsertUpdateOptions<T> & UpsertManyOptions<T, never> = {}
Returns Promise<QueryResult<T>>
inheritedreconnect
Closes all connections and re-establishes them.
Parameters
optionaloptions: { skipOnConnect?: boolean }
optionalskipOnConnect: boolean
Returns Promise<MongoConnection>
inheritedsetMetadata
Sets the metadata storage and initializes the comparator for all connections.
Parameters
metadata: MetadataStorage
Returns void
stream
Returns an async iterator that streams query results one entity at a time.
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: StreamOptions<T, any, any, any> & { rawResults?: boolean }
Returns AsyncIterableIterator<T, any, any>
streamAggregate
Parameters
entityName: EntityName<T>
pipeline: any[]
optionalctx: ClientSession
Returns AsyncIterableIterator<T, any, any>
streamVirtual
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
options: FindOptions<T, any, any, any>
Returns AsyncIterableIterator<EntityData<T>, any, any>
inheritedsyncCollections
Persists changes to M:N collections (inserts/deletes pivot table rows).
Parameters
collections: Iterable<Collection<T, O>, any, any>
optionaloptions: DriverMethodOptions
Returns Promise<void>
Database driver for MongoDB.