Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to query your data in mongoDB compass with case insensitive option?

I am trying to query data in MongoDB compass GUI based on multiple values using $in.

My query is this –

{category : {[$in: ['a012','b23c','5870T']}}

I want to query these values with case insensitive option i. The operator $in also doesn’t accept regex expressions as per documentation.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What would be the correct query with the case insensitive option included?

>Solution :

Try this:

db.mycollection.find({'category':{$in:[/a012/i, /b23c/i, /5870T/i]}})

To limit to the ‘word boundaries’ of the string, you can use \b

db.mycollection.find({'category':{$in:[/\ba012\b/i, /\bb23c\b/i, /\b5870T\b/i]}})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading