日期:2014-05-16 浏览次数:20921 次
{user_id, ......, consume{ ...., time, .... }, ...}
> db.consume.find({"consume.time.":{$gt:"0"}},{_id:0,user_id:1,"consume.time":1}).sort({"consuem.time":1}).limit(5); { "consume" : { "time" : "1314583316" }, "user_id" : "34800268" } { "consume" : { "time" : "1314583319" }, "user_id" : "67400937" } { "consume" : { "time" : "1314583321" }, "user_id" : "130041511" } { "consume" : { "time" : "1314583328" }, "user_id" : "4450046611" } { "consume" : { "time" : "1314583336" }, "user_id" : "20036266" }
db.consume.group({ key:{"user_id":true} ,cond:{"consume.time":{$gt:"1314583316",$lt:"1314583336"}},initial:{co:0},reduce:function(oj,pr){pr.co++} } )
DBCollection userSColl = MongoDBUtils.getDBCollection("consume"); BasicDBObject key = new BasicDBObject("user_id",true); BasicDBObject cond = new BasicDBObject("consume.time",new BasicDBObject("$gt","1314583316").append("$lt", "1314583336")); BasicDBObject initial = new BasicDBObject("cou",0); String reduce = "function(obj,pre){pre.cou++}"; BasicDBList returnList = (BasicDBList)userSColl.group(key, cond, initial, reduce);
List list = userSColl.distinct("user_id", new BasicDBObject("consume.time",new BasicDBObject("$gt","1314583316").append("$lt", "1314583336")));