歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

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);

Copyright © Linux教程網 All Rights Reserved