1.distinct以及distinct.length
mongoTemplate.getCollection(collectionName).distinct(field, query.getQueryObject());
mongoTemplate.getCollection(collectionName).distinct(field, query.getQueryObject()).size();
2.aggregate聚合函数的使用结合字符串截取
{ $project : { day : {$substr: ["$date", 0, 10] }}}
Aggregation agg = Aggregation.newAggregation(
Aggregation.project("a").and("date").substring(0,10).as("xday").and("d").as("e").and("f").as("d").and("a").as("w").and("x").as("x").and("z").as("z").and("a").as("a"),
Aggregation.match(criteria),
Aggregation.group("xday","messageType").count().as("sendAmount"),
Aggregation.sort(sort)
);
主要是网上mongodb资料太少,希望能给以后的朋友给到帮助。