this question has answer here:
- how query mongodb “like”? 29 answers
i want skip records db has string in java(using basicdboject). eg:
"description" field name in collection called "comment"
i don't want records has "test message" part of value in field "description".
please refer documentation @ http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/#getting-a-set-of-documents-with-a-query , http://api.mongodb.org/java/current/com/mongodb/querybuilder.html#regex%28java.util.regex.pattern%29, don't seem have put in effort researching yourself. code like:
mongo m = new mongo(); m.setwriteconcern(writeconcern.safe); dbcollection c = m.getdb("testdb").getcollection("collection"); pattern pattern = pattern.compile("test message"); dbobject query = querybuilder.start(). querybuilder.start("description").regex(pattern).get(); system.out.println(c.find(query).count());
Comments
Post a Comment