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.
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]}})