meteorhacks:aggregate

v1.3.0Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

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.

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

Using Options

1var result = new Mongo.Collection('metrics');
2var metrics = new Mongo.Collection('metrics');
3var pipeline = [
4  {$group: {_id: null, resTime: {$sum: "$resTime"}}}
5];
6var result = metrics.aggregate(pipeline, {explain: true});
7console.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)