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 ?
相关问题
- MongoDB can not create unique sparse index (duplic
- Spring Data MongoDB - lazy access to some fields
- Golang mongodb aggregation
- How to convert from Timestamp to Mongo ObjectID
- MongoDB Indexing: Multiple single-field vs single
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- MongoError: cannot infer query fields to set, path
- Pymongo $in Query Not Working
- django.core.exceptions.ImproperlyConfigured: '
- How does Cassandra scale horizontally ?
This works for me perfectly.
From code we can create custom query like this:
This will transform to following in mongo after query:
Same for "$nin".
Use $in with the match being case insensitive:
Data example:
And we want documents were "fieldX" is contained in any value of the array (optValues):
This works for $all either.
I hope this helps!
p.s.: This was my solution to search by tags in a web application.
You can use $elemMatch with regular expressions search, e.g. let's search for "blue" color in the following collection:
The way to do it in Java is:
Here is my case insensitive search (query) with multiple condition (regex) from data of array, I've used
$in
but it doesn't support case insensitive search.Example Data
My query
This is pretty simple