moringaman
7/11/2016 - 5:50 AM

Publish Aggregated Mongo Data to clientCollection

Publish Aggregated Mongo Data to clientCollection

//Publish aggrigated gamesSessions collection

Meteor.publish("gameAverages", function (){
  ReactiveAggregate(this, GameSessions,

    // Pipeline
    [
      // Stage 1
      {
        $group: {
        _id: null,
        Pwr: { $avg: '$Pwr'},
        Intvl: {$avg: '$Intvl'}
        }
      },

      {
        $project: {
            Pwr: '$Pwr',
            Intvl: '$Intvl'
            }
          }
        ], {
        // and send the results to another collection called below
        clientCollection: "GameReport"
    });
});