title: When performing an aggregate in mongodb using mongoose an empty object is returned, why is this?
body: <p>This is my first look in anger an node.js and mongodb so its possible I've done something silly or missed something obvious but given the document and the query below, why might a an empty object be returned?</p>
  
  <h2>1 Document example</h2>
  
  <pre><code>{  
      __v: 0, 
      _id: ObjectId("50bf7f12fc71b74f3b000001"),
      amount: 452.23, 
      categoryId: 13, 
      created: ISODate("2012-12-05T17:06:26Z"), 
      description: "Test", 
      typeId: 1, 
      updated: ISODate("2012-12-05T17:06:26Z")
  }
  </code></pre>
  
  <h2>2 Problem code</h2>
  
  <pre><code>var Schema = mongoose.Schema;  
  
  var Expense = new Schema({  
      description: { type: String, required: true },  
      amount: { type: Number, required: true },  
      created: { type: Date, default: Date.now },
      updated: { type: Date, default: Date.now },
      categoryId: { type: Number, required: true },
      typeId: { type: Number, required: true }
  });
  
  var ExpenseModel = mongoose.model('Expense', Expense);
  
  ExpenseModel.aggregate(  
      { $group: { _id: '$typeId', total: { $sum: '$amount' }}}, 
      function (err, summary) {
          if(err){
              return res.send(500, { error: err }); 
          }
  
          if(summary) {
              return res.send(summary);
          } else {
              res.send(500, { error: 'couldnt find expenses' }); 
          }
      }
  );
  </code></pre>