Can i group by $first

Loving Charts. I often use it only to export the aggregation pipeline json object so i can use it within my application. I find the charges aggregation pipeline editor is more intitule (drag and drop) then the Compass aggregation pipeline builder. I feel compass could learn to use the same editor as the charts editor.

Anyway, i am unable to group by $first

is it possible to get the first field in group by or even in the value?


Hi @Rishi_uttam ,

Sure you can, take for example the following documents and aggregation where there is a groups array with order of groups registered and score of the competition.

Now we can group the documents based on the first group and calculate the avg score:

[{$group: {
 _id: {
  group: {
   $first: '$group'
 avgScore: {
  $avg: '$score'