How to write Like query in mongodb using java driver

35 views
Skip to first unread message

hitesh kumar

unread,
Apr 13, 2012, 7:24:05 AM4/13/12
to mongodb-user
Hi all,
Currently I am using java to connect to MONGODB,
i want to write this sql query in mongodb using java driver

select * from tableA where name like("%ab%")

now is their any solution to perform the same task through java,

the query in mongodb is very simple i know, the query is
db.collection.find({name:\ab\})

but how to perform same task in java

Current I am using pattern matching to perform the task and code is
DBObject A = QueryBuilder.start("name").is(Pattern.compile("ab",
Pattern.CASE_INSENSITIVE)).get();

but it makes query very slow I think , so I need a solution other than
this pattern matching,

So, it their is any solution available, Please contribute,,

thanks in advance

Andreas Jung

unread,
Apr 13, 2012, 7:29:53 AM4/13/12
to mongod...@googlegroups.com
MongoDB like most other database can not perform arbitrary
fulltext operations - in particular substring searches - effectively.
You are clearly looking for an external fulltext solution.

-aj

--
ZOPYX Limited | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 T�bingen | Produce & Publish
www.zopyx.com | www.produce-and-publish.com
------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


Reply all
Reply to author
Forward
0 new messages