Java实现对MongoDB的OR操作

直接用代码表示吧,留意BasicDBList使用就行了

DBObject query = new BasicDBObject();
                    query.put("agent_id", 511);
                    query.put("switchSn", "交96");
                    query.put("ds_name", "trafficin_eth0");
                    query.put("relay_ip", "192.168.239.176");
                    BasicDBList values = new BasicDBList();
                    values.add(new BasicDBObject("time", new BasicDBObject("$gte", DateUtil.getInstance().getDateTimeStrMultiThread("2011-07-24 00:00:00").getTime()).append("$lte", DateUtil.getInstance().getDateTimeStrMultiThread("2011-07-27 23:59:59").getTime())));
                    values.add(new BasicDBObject("time", new BasicDBObject("$gte", DateUtil.getInstance().getDateTimeStrMultiThread("2011-07-28 00:00:00").getTime()).append("$lte", DateUtil.getInstance().getDateTimeStrMultiThread("2011-07-29 23:59:59").getTime())));              
                    query.put("$or", values);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjggj.html