MongoDB aggregation but not including certain items
<p>I'm very new to MongoDB's aggregation framework, so I do not know properly how to do this.</p>

<p>I have a data model that is structured like this:</p>

<pre><code>{
  name: String,
  store: {
    item1: Number,
    item2: Number,
    item3: Number,
    item4: Number,
  },
  createdAt: Date
}
</code></pre>

<p>I want to return the average price of every item'i'. I'm trying with this query:</p>

<pre><code>db.commerces.aggregate([
   {
      $group: {
        _id: "",
        item1Avg: { $avg: "$store.item1"},
        item2Avg: { $avg: "$store.item2"},
        item3Avg: { $avg: "$store.item3"},
        item4Avg: { $avg: "$store.item4"}
      }
   }
]);
</code></pre>

<p>The problem is that when an item has no price set, it's stored in the database as a "-1".</p>

<p>I don't want these values to pollute the average result. Is there any way to limit the agreggation to only take into account when price is > 0.</p>

<p><code>$match</code> operator before <code>$group</code> is not a solution because I want to return all the average prices.</p>

<p>Thank you!</p>

<p><strong>EDIT</strong>: Here you have of an example of the input &amp; desired output:</p>

<pre><code>[{
  name: 'name',
  store: {
    item1: 10,
    item2: -1,
    item3: 12,
    item4: 3,
  }
},
{
  name: 'name2',
  store: {
    item1: 10,
    item2: -1,
    item3: -1,
    item4: 2,
  }
},...]
</code></pre>

<p>An the desired output:</p>

<pre><code>{
  item1Avg: 10,
  item2Avg: 0,
  item3Avg: 12,
  item4Avg: 2.5
}
</code></pre>