Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mongo): move $fulltext from $and to top level (#4066)
Closes #4065 --------- Co-authored-by: Martin Adámek <banan23@gmail.com>
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MikroORM } from '@mikro-orm/mongodb'; | ||
|
||
import { Author, Book } from '../entities'; | ||
import { closeReplSets, initORMMongo } from '../bootstrap'; | ||
|
||
describe('GH4065', () => { | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => orm = await initORMMongo(true)); | ||
beforeEach(async () => orm.schema.clearDatabase()); | ||
|
||
afterAll(async () => { | ||
await orm.close(); | ||
await closeReplSets(); | ||
}); | ||
|
||
test('should load entities with $fulltext and filter set', async () => { | ||
const god = new Author('God', 'hello@heaven.god'); | ||
const bible = new Book('Bible', god); | ||
await orm.em.persistAndFlush(bible); | ||
orm.em.clear(); | ||
|
||
const booksRepository = orm.em.getRepository(Book); | ||
orm.em.addFilter('BreakFulltext', { title: { $re: '.*' } }, Book, true); | ||
const books = await booksRepository.find({ $fulltext: 'Bible' }); | ||
expect(books.length).toBe(1); | ||
}); | ||
}); |