DEV Community

Nisa JThani
Nisa JThani

Posted on

Case insensitive queries with LoopBack 4

My first post!

If the results of the query must contain the upper or lower case of some text, you will need to do a case-insensitive RegExp search:

const someText = 'black';
const pattern = new RegExp('.*' + someText + '.*', "i"); /* Case-insensitive RegExp search. The second argument is the case insensitive flag */
Cat.find({
where: {
adopted: false,
or: [
{ name: { regexp: pattern } },
{ description: { regexp: pattern } }
]
}
});

Note: I used MongoDB for my database.

Top comments (0)