Skip to content

Commit

Permalink
fix(mongo): add support for $re operator in mongo
Browse files Browse the repository at this point in the history
Closes #613
  • Loading branch information
B4nan committed Aug 9, 2020
1 parent 414463b commit 13fe6e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/mongodb/src/MongoDriver.ts
Expand Up @@ -223,6 +223,10 @@ export class MongoDriver extends DatabaseDriver<MongoConnection> {
data[k] = this.convertObjectIds(data[k]);
}
}

if (Utils.isPlainObject(data[k]) && '$re' in data[k]) {
data[k] = new RegExp(data[k].$re);
}
});

return data;
Expand Down
6 changes: 6 additions & 0 deletions tests/EntityManager.mongo.test.ts
Expand Up @@ -422,6 +422,12 @@ describe('EntityManagerMongo', () => {
expect(authors[0].name).toBe('Author 1');
expect(authors[1].name).toBe('Author 2');
expect(authors[2].name).toBe('Author 3');

const authors2 = await orm.em.find(Author, { email: { $re: 'example.com$' } });
expect(authors2.length).toBe(3);
expect(authors2[0].name).toBe('Author 1');
expect(authors2[1].name).toBe('Author 2');
expect(authors2[2].name).toBe('Author 3');
});

test('stable results of serialization', async () => {
Expand Down

0 comments on commit 13fe6e5

Please sign in to comment.