spring data mongodb高级查询语句的使用(网上基本没资料)

来源:互联网 发布:米兔积木机器人 编程 编辑:程序博客网 时间:2024/06/11 22:39

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资料太少,希望能给以后的朋友给到帮助。

原创粉丝点击