1 回答

TA貢獻1951條經(jīng)驗 獲得超3個贊
前面給你都是直接的mango查詢語句,使用客戶端可以。我寫過一個java的,給你參照一下。我這里分組查詢之后還排序了、
MongoClient mongo = getMangoDB();
collection = getDBConnect("tb_link",mongo);
//Date end = new Date();
Date end = df_yMdHm.parse("2017-11-10 09:10:00");
Date start = new Date(end.getTime() - delay_time);
BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("area", areakey);
searchQuery.put("server_type", server_type);
searchQuery.put("time", new BasicDBObject("$gte", start).append("$lt", end));
BasicDBObject showdata = new BasicDBObject();
showdata.put("server_ip", 1);
showdata.put("count", 1);
FindIterable<Document> findIterable = collection.find(searchQuery).sort(new BasicDBObject("time", 1)); MongoCursor<Document> mongoCursor = findIterable.iterator();
添加回答
舉報