case insensitive search using java driver

1,023 views
Skip to first unread message

Abhishek kumar

unread,
Nov 24, 2011, 9:54:34 PM11/24/11
to mongodb-user
How to use case insensitive search in java, mongo

Right now I am using:
basicDBObject.append("attribute", Pattern.compile(".*(" +
keywordsPattern + ").*")); // this is case-sensitive

I want "keywordsPattern" to be case insensitive

I know how it is done in mongo shell( using /i ), but dont know how to
translate the same in mongo java driver queries

Ekin Koc

unread,
Nov 24, 2011, 10:21:32 PM11/24/11
to mongodb-user
On Nov 25, 4:54 am, Abhishek kumar <abhishekiit...@gmail.com> wrote:
> How to use case insensitive search in java, mongo
>
> Right now I am using:
>             basicDBObject.append("attribute", Pattern.compile(".*(" +
> keywordsPattern + ").*"));   // this is case-sensitive

I have not used the Java driver, but creating the Pattern with case
insensitive flag should work (at least it does in c# driver)

Pattern.compile("REGEX", Pattern.CASE_INSENSITIVE);

--
Ekin Koc

gen liu

unread,
Nov 24, 2011, 11:59:14 PM11/24/11
to mongodb-user
As Ekin Koc said, you can using Pattern like:
Pattern.compile("REGEX", Pattern.CASE_INSENSITIVE);

Abhishek kumar

unread,
Nov 25, 2011, 1:31:42 AM11/25/11
to mongodb-user
thanks, it is working now :)
Reply all
Reply to author
Forward
0 new messages