モンゴ集計ノート

モンゴは、多くの単語を書くのに慣れていないため、使いにくい

ドキュメントは非常によく書かれています。

https://docs.mongodb.com/manual/reference/aggregation-variables/#agg-system-variables

 

 

https://docs.mongodb.com/manual/reference/operator/aggregation/sort/index.html

 

 

 

 

https://docs.mongodb.com/manual/reference/operator/aggregation/group/index.html

 

 

 

 

この記事は大丈夫です。

https://www.jianshu.com/p/206f036bdfc5

 

Springbootのmongtemplateに対応して、こう書いてある

 

 

 

これはとてもよく書かれています

https://kb.objectrocket.com/mongo-db/mongodb-group-by-multiple-fields-using-aggregation-function-464

 

db.sales.aggregate(
   [ 
     {ソート$:{アイテム: -1、日付:-1 }、
     { 
       $基:
         { 
           _id: "$項目" 
           firstSalesDate:{$最初: "$日付" }、
           firstId。 {$ first: "$ _id" }、
           firstRoot:{$ first: "$$ ROOT" }、
         } 
     } 
   ] 

  

基準基準= Criteria.where( "xxx")。is( "xxxx")。and( "xxx")。is(xxx);        
集約集約= Aggregation.newAggregation( Aggregation.match(criteria)、 Aggregation.sort(Sort.Direction.ASC、 "createTime" )、 Aggregation.group( "xx"、 "xx" ). first( "$ id")。 as( "xx" ). first( "$ xxx")。as( "xx" ). first( "$ xxx")。as( "xx" ). first( "$ xxxx")。as( " .first( "$ xxxx")。as( "xx" );

より多くの落とし穴は、$ _idがmongotemplateで$ idと呼ばれることであり、より少ない_、およびAggregation.ROOT、Aggregation.CURRENT

 

おすすめ

転載: www.cnblogs.com/tekikesyo/p/12703774.html