title: Aggregation mongodb grouping by a value
body: <p>I have the followings documents of a mongodb collection:</p>
  <pre><code>{
  &quot;year&quot;: 2020,
  &quot;cod&quot;: 4241,
  &quot;op&quot;: &quot;12&quot;
  }
  
  {
  &quot;year&quot;: 2021,
  &quot;cod&quot;: 2241,
  &quot;op&quot;: &quot;34&quot;
  }
  
  {
  &quot;year&quot;: 2020,
  &quot;cod&quot;: 4325,
  &quot;op&quot;: &quot;54&quot;
  }
  
  {
  &quot;year&quot;: 2021,
  &quot;cod&quot;: 1132,
  &quot;op&quot;: &quot;A3&quot;
  }
  </code></pre>
  <p>I need an aggregator that let me group these documents by the year, in this way:</p>
  <pre><code>{
  &quot;year&quot;: 2020,
  &quot;values&quot;: [{&quot;cod&quot;:4241, &quot;op&quot;:&quot;12&quot;}, {&quot;cod&quot;:4325, &quot;op&quot;:&quot;54&quot;}]
  }
  
  {
  &quot;year&quot;: 2021,
  &quot;values&quot;: [{&quot;cod&quot;:2241, &quot;op&quot;:&quot;34&quot;}, {&quot;cod&quot;:1132, &quot;op&quot;:&quot;A3&quot;}]
  } 
  </code></pre>