title: Is it possible to use` $sum` in the `$match` stage of mongo aggregation and how?
body: <p>I have a <code>gifts</code> collection in mongodb with four items inside it. how do I query the db so that I get only gifts that the sum of their <code>amount</code> is less-than-or-equal-to 5500? 
     so for example from these four gifts in db:    </p>
  
  <pre><code>{
     "_id": 1,
     "amount": 3000,
  }, 
  {
     "_id": 2,
     "amount": 2000,
  },
  {
     "_id": 3,
     "amount": 1000,
  },
  {
     "_id": 4,
     "amount": 5000,
  }
  </code></pre>
  
  <p>The query should return the first two only:</p>
  
  <pre><code>{
     "_id": 1,
     "amount": 3000,
  }, 
  {
     "_id": 1,
     "amount": 2000,
  },
  </code></pre>
  
  <p>I think I should use mongo <strong>aggregation</strong>? if so, what is the syntax?<br>
  I had some googling, I know how to use <code>$sum</code> in the <code>$group</code> stage, but I don't know how to use it in the <code>$match</code> stage. is it event possible to do so?</p>
  
  <p>P.S: I assumend I should use <code>$sum</code> in <code>$match</code>, Am I supposed to group them first? if so, how do I tell mongo to make a group where the sum of amounts in that group is less-than-or-equal-to 5500?</p>
  
  <p>Thanks for any help you are able to provide.</p>