title: Populate + Aggregate in Mongoose
body: <p>I have two Mongoose models: one for transactions and the other one for the tags associated with them. In order to implement some reports, I need aggregate code like this:</p>
  
  <pre><code>Transaction.aggregate([
    { $unwind: '$tags' },
    {
      $group: {
        _id: '$tags',
        amount: {
          $sum: '$amount'
        }
      }
    }
  ])
  </code></pre>
  
  <h2>Question</h2>
  
  <p>This produces output containing <code>_id</code> and <code>amount</code>. Now, I'd like to populate the other fields (e.g. <code>name</code>) from the model, keeping the calculated <code>amount</code> column. Can I do that within a simple <code>populate</code>?</p>
  
  <h2>Edit</h2>
  
  <p>The schemas for the models I'm describing:</p>
  
  <pre><code>var TransactionSchema = new Schema({
    description: {
      type: String,
      trim: true
    },
    amount: {
      type: Number,
      required: 'Forneça um valor',
    },
    date: {
      type: Date,
      required: 'Forneça uma data',
      default: Date.now
    },
    fromOfx: {
      type: Boolean,
      default: false
    },
    created: {
      type: Date,
      default: Date.now
    },
    correlated: {
      type: Boolean,
      default: false
    },
    tags: [{
      type: Schema.Types.ObjectId,
      ref: 'TransactionTag'
    }],
    correlates: [{
      type: Schema.Types.ObjectId,
      ref: 'Transaction'
    }],
    user: {
      type: Schema.Types.ObjectId,
      ref: 'User'
    }
  });
  
  var TransactionTagSchema = new Schema({
    name: {
      type: String,
      required: 'Forneça um nome',
      trim: true
    },
    description: {
      type: String,
      trim: true
    },
    amount: {
      type: Number
    }
  });
  </code></pre>