【转】Java实现对MongoDB的AND、OR和IN操作
@Testpublic void testIn(){DBObject queryCondition = new BasicDBObject();//age in [13, 47]queryCondition = new BasicDBObject();BasicDBList values = new BasicDBList();values.add(13);values.add(47);queryCondition.put("age", new BasicDBObject("$in", values));DBCursor dbCursor = coll.find(queryCondition);assertEquals(2, dbCursor.size());assertEquals("tom", dbCursor.next().get("username"));}
?
???从以上几个例子可以看出,通过BasicDBList与BasicDBObject的相结合可以得出比较复杂的查询条件。
?
转自:http://blog.csdn.net/mydeman/article/details/6652387