title: Mongo group aggregation with priority of record
body: <p>I am trying to perform a MongoDB 3.6 aggregation and I can't figure out the right way.</p>
  
  <p>The problem is following. After performing several aggregation steps I end up with result set like this:</p>
  
  <pre><code>[
    { _id: { month: 1, type: 'estimate' }, value: 50 },
    { _id: { month: 2, type: 'estimate' }, value: 40 },
    { _id: { month: 3, type: 'estimate' }, value: 35 },
    { _id: { month: 3, type: 'exact' }, value: 33.532 },
    { _id: { month: 4, type: 'estimate' }, value: 10 },
    { _id: { month: 4, type: 'exact' }, value: 11.244 },
  ]
  </code></pre>
  
  <p>It contains values grouped by month. Value for every month can be 'estimated' or 'exact'. Now I would like to reduce this result to achieve this:</p>
  
  <pre><code>[
    { _id: { month: 1 }, value: 50 },
    { _id: { month: 2 }, value: 40 },
    { _id: { month: 3 }, value: 33.532 },
    { _id: { month: 4 }, value: 11.244 },
  ]
  </code></pre>
  
  <p>Basically I want to use the value of type 'exact' whenever it's possible and only fallback to 'estimate' value in months where the 'exact' is not known. </p>
  
  <p>Any help or tip will be greatly appreciated. I would like to perform that aggregation in the DB not on server.</p>