ReactiveAggregate

ReactiveAggregate

new ReactiveAggregate(pub, collection, pipeline, options)

Provides a wrapper around the results of a Mongo aggregate query to make it Reactive

Source:
Example
// ## Quick Example
 //
 // A publication for one of the
 //   [examples](https://docs.mongodb.org/v3.0/reference/operator/aggregation/group/#group-documents-by-author)
 // in the MongoDB docs would look like this:
 //
 // Meteor.publish("booksByAuthor", function () {
//   ReactiveAggregate(this, Books, [{
//     $group: {
//       _id: "$author",
//       books: { $push: "$$ROOT" }
//     }
//   }]);
// });
Parameters:
Name Type Description
pub Object

The instance of the publication we are creating

collection Object

The Mongo.Collection instance to query

pipeline Array

The aggregation pipeline to use

options Object

Optional options

  • observeSelector can be given to improve efficiency. This selector is used for observing the collection. // (e.g. { authorId: { $exists: 1 } }) // - observeOptions can be given to limit fields, further improving efficiency. Ideally used to limit fields on your query. // If none is given any change to the collection will cause the aggregation to be reevaluated. // (e.g. { limit: 10, sort: { createdAt: -1 } }) // - clientCollection defaults to collection._name but can be overriden to sent the results // to a different client-side collection.