Skip to content

Commit

Permalink
feat(mongo): add getCollection() method to MongoEntityManager
Browse files Browse the repository at this point in the history
shortcut for `em.getConnnection().getCollection()`
  • Loading branch information
B4nan committed Aug 9, 2020
1 parent e389d40 commit 79a9a7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/mongodb/src/MongoEntityManager.ts
@@ -1,6 +1,7 @@
import { AnyEntity, EntityManager, EntityName, EntityRepository, Utils } from '@mikro-orm/core';
import { MongoDriver } from './MongoDriver';
import { MongoEntityRepository } from './MongoEntityRepository';
import { Collection } from 'mongodb';

/**
* @inheritDoc
Expand All @@ -15,6 +16,10 @@ export class MongoEntityManager<D extends MongoDriver = MongoDriver> extends Ent
return this.getDriver().aggregate(entityName, pipeline);
}

getCollection(entityName: EntityName<AnyEntity>): Collection {
return this.getConnection().getCollection(entityName);
}

getRepository<T extends AnyEntity<T>, U extends EntityRepository<T> = MongoEntityRepository<T>>(entityName: EntityName<T>): U {
return super.getRepository<T, U>(entityName);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/EntityManager.mongo.test.ts
Expand Up @@ -481,7 +481,7 @@ describe('EntityManagerMongo', () => {
await expect(driver.loadFromPivotTable({} as EntityProperty, [])).rejects.toThrowError('MongoDriver does not use pivot tables');
await expect(driver.getConnection().execute('')).rejects.toThrowError('MongoConnection does not support generic execute method');
expect(driver.getConnection().getCollection(BookTag).collectionName).toBe('book-tag');
expect(driver.getConnection().getCollection(BookTag.name).collectionName).toBe('book-tag');
expect(orm.em.getCollection(BookTag).collectionName).toBe('book-tag');
});

test('ensure indexes', async () => {
Expand Down

0 comments on commit 79a9a7d

Please sign in to comment.