Date lastExcTime=new Date();
long startIndex=0;
int pageSize=10;
List pipeline = new ArrayList();
BasicDBObject group = new BasicDBObject();
BasicDBObject val = new BasicDBObject();
val.append("_id","$userId");
val.append("createTime",new BasicDBObject("$max","$createTime"));
group.append("$group", val);
pipeline.add(group);
BasicDBObject match = new BasicDBObject();
BasicDBObject matchVal = new BasicDBObject();
matchVal.append("createTime",new BasicDBObject("$gte",lastExcTime));
match.append("$match", matchVal);
pipeline.add(match);
BasicDBObject project = new BasicDBObject();
BasicDBObject projectVal = new BasicDBObject();
projectVal.append("createTime",1);
projectVal.append("userId",1);
projectVal.append("_id",-1);
project.append("$project", projectVal);
pipeline.add(project);
pipeline.add(new BasicDBObject("$skip",startIndex));
pipeline.add(new BasicDBObject("$limit",pageSize));
AggregationOutput aggregate = mongoTemplate.getCollection("homeLog").aggregate(pipeline);
HomeLog log=new HomeLog();
List list=new ArrayList();
JSONArray bean=JSONArray.parseArray(aggregate.getCommandResult().getString("result"));
for (int i = 0; i < bean.size(); i++) {
log = JSONObject.toJavaObject(bean.getJSONObject(i),HomeLog.class);
list.add(log);
}