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


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


          網站導航:
           
          主站蜘蛛池模板: 石狮市| 宜兴市| 突泉县| 江北区| 双柏县| 甘南县| 天门市| 昌江| 油尖旺区| 广安市| 克山县| 江山市| 渝北区| 应城市| 桃江县| 新泰市| 孝昌县| 福建省| 昆山市| 冀州市| 中阳县| 山阳县| 修文县| 池州市| 寻甸| 丹江口市| 柳河县| 墨竹工卡县| 略阳县| 乌兰察布市| 宁陕县| 全椒县| 芒康县| 法库县| 古丈县| 泸西县| 花莲市| 景宁| 扎赉特旗| 太和县| 通化县|