1

I want to skip some records from DB which has some string in Java(using BasicDBOject). Say for eg:

"description" is my field name in a collection called "comment"

I don't want the records which has "Test message" as part of the value in field "description".

4

1 回答 1

1

请参阅http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/#getting-a-set-of-documents-with-a-queryhttp:// /api.mongodb.org/java/current/com/mongodb/QueryBuilder.html#regex%28java.util.regex.Pattern%29,因为您似乎并没有花太多精力自己研究这个。代码看起来像:

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());
于 2013-07-15T08:57:16.150 回答