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 閱讀(216) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 乐平市| 交口县| 盐城市| 察雅县| 章丘市| 汉寿县| 垫江县| 红原县| 额尔古纳市| 乐亭县| 建阳市| 台湾省| 沙坪坝区| 九龙城区| 常山县| 龙胜| 永和县| 郎溪县| 德清县| 横峰县| 新建县| 横山县| 新津县| 朝阳县| 司法| 青龙| 定边县| 樟树市| 伊春市| 建宁县| 无锡市| 甘德县| 庐江县| 望江县| 衡山县| 郑州市| 木兰县| 东阿县| 金沙县| 彩票| 和硕县|