Java中mongodb使用and和or的复合查询

条件类似:a=5 or (a=2 and b>3)
BasicDBList endList = new BasicDBList();

BasicDBObject forceEnd = new BasicDBObject();
forceEnd.put("status", 5);

BasicDBList condList = new BasicDBList();
BasicDBObject autoEnd = new BasicDBObject();
condList.add(new BasicDBObject("status", 2));
condList.add(new BasicDBObject("endTime", new BasicDBObject("$lt", new Date())));
autoEnd.put("$and",condList);

endList.add(forceEnd);
endList.add(autoEnd);

basicDBObject.put("$or",endList);
posted @ 2016-11-25 14:01  lcpnene  阅读(6639)  评论(0编辑  收藏  举报