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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay