Aggregation mongodb grouping by a value

db.collection.aggregate([
{
$group: {
  _id: "$year",
  values: {
    $push: {
      cod: "$cod",
      op: "$op"
    }
  }
 }
},
{
 $project: {
  year: "$_id",
  values: 1,
  _id: 0
 }
}
])
Topics: MongoDB

Related Code Examples