java mongo 查询统计 distinct

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>


Date lastExcTime=new Date();


CommandResult result = mongoTemplate.getDb().command(

new BasicDBObject("distinct", "homeLog").append("key",

"userId").append(

"query",

new BasicDBObject("createTime", new BasicDBObject(

"$gte", lastExcTime))));

JSONArray bean=JSONArray.parseArray(result.getString("values"));

                        System.out.println(bean.size());