Mongoose/Express : average of subdocuments

I have the following models :

Product :

var ProductSchema = new Schema({
name: String,
comments: [{ type: Schema.Types.ObjectId, ref: 'Comment'}],
_user: { type: Schema.Types.ObjectId, ref: 'User'}
});

Comment :

var CommentSchema = new Schema({
text: String,
rating: Number,
_product: { type: Schema.Types.ObjectId, ref: 'Product'}
});

What I do currently is retrieve all Products along with their user :

router.get('/', function(req, res, next) {
Product.find().populate('_user').exec(function (err, products) {
    if (err) return next(err);
    res.json(products);
});
});

I'd like to add to the results an "average" field that contains the average of all comments for each product so the results would look like this :

[{name: "Product 1", _user: {name: "Bob"}, average: 7.65},...]

Is this possible with a unique query ? Do I need to compute and store the average in the Product document each time a new Comment is added ?

Thanks !

Maybe you should try with calculating the "Running Average". You only need to know how many ratings there are, and what is their average. Having same average value saved for every document in MongoDB should be bad practice, I hope this will help you. So you could create schema like this:

var AverageProductRatingSchema = new Schema({
  productId:       {type: Schema.Types.ObjectId, ref: 'Product'},
  averageRating:   {type: Number},
  numberOfRatings: {type: Number}
});

Then just implement addRating() function something like this:

function addRating(newRating, productId) {
  /* Find document that holds average rating of wanted product */
  AverageProductRating.findOneAsync({productId: productId})
    .then(function (avgProdRating) {

       /* 
         Calculate new average using the Running Average method.
         http://www.bennadel.com/blog/1627-create-a-running-average-without-storing-individual-values.htm
       */
       var newAverageRating = (avgProdRating.averageRating * avgProdRating.numberOfRatings + newRating) / (avgProdRating.numberOfRatings + 1);
       var newNumberOfRatings = avgProdRating.numberOfRatings + 1;

       AverageProductRating.update(
         { productId: productId },
         {
           $set: {
             averageRating:   newAverageRating,
             numberOfRatings: newNumberOfRatings 
         }
       });
     });

}

This is the link that describes similiar issue: http://www.bennadel.com/blog/1627-create-a-running-average-without-storing-individual-values.htm