Case insensitive search (via regex operator) in MongoDB
It would be fine to have the possibility to search case insensitive within mongodb.
At this time a query like this is needed to include lower case words:
title=re=.*Bluetooth.* or title=re=.*bluetooth.*
Agreed. Even an case a insensitive substring search?
title=~=luetooth
I've largely operated under the thinking that regular expressions are enough for the problems listed here until they prove to be unacceptable for some reason. Historically, mongo's case sensitivity story has not been great until just last month:
https://jira.mongodb.org/browse/SERVER-90
If there's a way to benefit from the recent developments in mongo I would probably recommend it be implemented as a custom visitor if possible!
Can you document how to express regex case insensitive substring match in url form?
For clients transforming:
q=~=mith (finds Smiths) to the case-insensitive regex criteria would simplify things.
On Thu, Sep 22, 2016 at 2:13 PM, Paul Rutledge [email protected] wrote:
I've largely operated under the thinking that regular expressions are enough for the problems listed here until they prove to be unacceptable for some reason. Historically, mongo's case sensitivity story has not been great until just last month:
https://jira.mongodb.org/browse/SERVER-90
If there's a way to benefit from the recent developments in mongo I would probably recommend it be implemented as a custom visitor if possible!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/RutledgePaulV/rest-query-engine/issues/11#issuecomment-248983287, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFkK1goN-3_t5ol1lOZjXWx1Az_QnGRks5qssVWgaJpZM4JlPED .
Hi guys,
I would like to up vote this issue. Our current setup is MongoDB 3.4 with featureCompatibilityVersion set to 3.4 and on collection level we have set collations with strength 2. When we are filtering for exact match we achieve the case insensitivity, for example suppose I have a user with first name set to "Svetlin" both calls:
/users?q=firstName==Svetlin /users?q=firstName==svetlin
will result in finding this user.
However, now we want to achieve autocompletion (sth like a "like" statement in regular RDBs). Of course, as we are using mongo we use the regex filtering, sth like:
/users?q=firstName=re=Sve.* (correctly retrieves the above user)
Unfortunately, I would expect that
/users?q=firstName=re=sve.*
will also work, which is not the case. Any suggestions how I can achieve both case insensitivity and autocompletion?
Best regards, Svetlin
We had the same issue. One of the senior guys in our team found out the code in q-builders and came up with overriding the MongoVisitor class - https://github.com/RutledgePaulV/q-builders/blob/develop/src/main/java/com/github/rutledgepaulv/qbuilders/visitors/MongoVisitor.java, so create your own
public class CustomMongoVisitor extends MongoVisitor{
@Override
protected Criteria visit(ComparisonNode node) {
// all the existing code of that function
// just change
else if (ComparisonOperator.RE.equals(operator)) {
return where(field).regex((String)single(values), "i"); // adding case insensitive using i
}
}
}```