-
-
Notifications
You must be signed in to change notification settings - Fork 494
/
MongoEntityManager.ts
27 lines (22 loc) · 990 Bytes
/
MongoEntityManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { AnyEntity, EntityManager, EntityName, EntityRepository, GetRepository, Utils } from '@mikro-orm/core';
import { MongoDriver } from './MongoDriver';
import { MongoEntityRepository } from './MongoEntityRepository';
import { Collection } from 'mongodb';
/**
* @inheritDoc
*/
export class MongoEntityManager<D extends MongoDriver = MongoDriver> extends EntityManager<D> {
/**
* Shortcut to driver's aggregate method. Available in MongoDriver only.
*/
async aggregate(entityName: EntityName<any>, pipeline: any[]): Promise<any[]> {
entityName = Utils.className(entityName);
return this.getDriver().aggregate(entityName, pipeline);
}
getCollection(entityName: EntityName<any>): Collection {
return this.getConnection().getCollection(entityName);
}
getRepository<T extends AnyEntity<T>, U extends EntityRepository<T> = MongoEntityRepository<T>>(entityName: EntityName<T>): GetRepository<T, U> {
return super.getRepository<T, U>(entityName);
}
}