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)

Image of Timescale

πŸ“Š Benchmarking Databases for Real-Time Analytics Applications

Benchmarking Timescale, Clickhouse, Postgres, MySQL, MongoDB, and DuckDB for real-time analytics. Introducing RTABench πŸš€

Read full post β†’

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay