How to search a column in a collection in mongodb with $in
which includes an array of elements for search and also caseInsensitive
matching of those elements in the column ?
You can use $elemMatch with regular expressions search, e.g. let's search for "blue" color in the following collection:
db.items.save({ name : 'a toy', colors : ['red', 'BLUE'] })
> ok
db.items.find({ 'colors': { $elemMatch: { $regex: 'blue', $options: 'i' } } })
>[ { "name": "someitem", "_id": { "$oid": "4fbb7809cc93742e0d073aef"}, "colors": ["red", "BLUE"] } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With