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)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 镇平县| 丽江市| 甘南县| 浪卡子县| 海南省| 高淳县| 福海县| 凭祥市| 衡山县| 巍山| 沂水县| 邢台市| 九寨沟县| 灵宝市| 琼海市| 得荣县| 淳化县| 丰原市| 晋城| 宕昌县| 平凉市| 韩城市| 万年县| 通河县| 新晃| 潢川县| 鄂托克前旗| 利辛县| 白沙| 闵行区| 呈贡县| 阜阳市| 中宁县| 乐安县| 渭南市| 伊吾县| 霍城县| 尼勒克县| 泉州市| 英山县| 陆河县|