java mongo 查询统计 distinct

2019PHP高薪工程师学习路线图....>>>


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