Proper MongoDB aggregations support for Meteor
JavaScript
Switch branches/tags
Clone or download
Permalink
Failed to load latest commit information.
.travis.yml Using only with new Meteor Aug 13, 2015
LICENSE added LICENSE Oct 26, 2014
README.md Allow to pass objects Aug 13, 2015
index.js Allow to pass objects Aug 13, 2015
package.js v1.3.0 Aug 13, 2015
test.js Allow to pass objects Aug 13, 2015

README.md

meteorhacks:aggregate

A simple package to add proper aggregation support for Meteor. This package exposes .aggregate method on Mongo.Collection instances.

this only works on server side and there is no oberserving support or reactivity built in

Usage

Add to your app with

meteor add meteorhacks:aggregate

Then simply use .aggregate function like below.

var metrics = new Mongo.Collection('metrics');
var pipeline = [
  {$group: {_id: null, resTime: {$sum: "$resTime"}}}
];
var result = metrics.aggregate(pipeline);

Using Options

var result = new Mongo.Collection('metrics');
var metrics = new Mongo.Collection('metrics');
var pipeline = [
  {$group: {_id: null, resTime: {$sum: "$resTime"}}}
];
var result = metrics.aggregate(pipeline, {explain: true});
console.log("Explain Report:", JSON.stringify(result[0]), null, 2);

Why?

There are few other aggregation packages out there. All of them written with some complex hacks and there are some easy way to do things. They also don't work with custom Mongo drivers as well.

And this package is short and simple. (~20 LOC)