paulwong

          spring data mongodb group by month

          https://stackoverflow.com/questions/35312677/how-to-use-month-using-aggregation-in-spring-data-mongo-db
          Aggregation agg = newAggregation(
              project("id")
                  .andExpression("month(createdDate)").as("month_joined")
                  .andExpression("year(createdDate)").as("year"),
              match(Criteria.where("year").is(2016)),
              group("month_joined").count().as("number"),
              project("number").and("month_joined").previousOperation(),
              sort(ASC, "number")
          );

          AggregationResults<JoinCount> results = mongoTemplate.aggregate(agg, 
                                                               "collectionName", JoinCount.class);
          List<JoinCount> joinCount = results.getMappedResults();

          posted on 2020-12-11 16:53 paulwong 閱讀(220) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 合山市| 井研县| 义马市| 徐州市| 白山市| 垦利县| 余江县| 南木林县| 灵山县| 南投市| 绥化市| 开封县| 镇安县| 吉林市| 亚东县| 万荣县| 河西区| 垣曲县| 抚宁县| 广平县| 罗平县| 仪陇县| 凤城市| 巩留县| 济宁市| 贵溪市| 克拉玛依市| 海伦市| 达州市| 永吉县| 钟祥市| 师宗县| 铁岭县| 涟源市| 德安县| 上高县| 崇阳县| 枣庄市| 高唐县| 榕江县| 老河口市|