java - Create aggregation in mongodb with spring -


i have aggregation works in mongo , need create exact 1 in java spring. didn't find way. know if there one?

db.collection_name.aggregate([      {          $group: {              _id : {                  year : {$year : "$receiveddate" },                  month : {$month: "$receiveddate"},                  day : { $dayofmonth : "$receiveddate"}             },             count : { $sum: 1 }         }     } ]) 

you try projecting fields first using spel andexpression in projection operation , group new fields in group operation:

aggregation agg = newaggregation(     project()                .andexpression("year(receiveddate)").as("year")         .andexpression("month(receiveddate)").as("month")         .andexpression("dayofmonth(receiveddate)").as("day"),     group(fields().and("year").and("month").and("day"))              .count().as("count") ); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -