meteorhacks/meteor-aggregate

Name: meteor-aggregate

Owner: meteorhacks

Description: Proper MongoDB aggregations support for Meteor

Created: 2014-10-25 23:51:46.0

Updated: 2018-03-07 02:54:53.0

Pushed: 2017-10-27 13:38:51.0

Homepage: null

Size: 202

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

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

or add meteorhacks:aggregate

Then simply use .aggregate function like below.

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

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

result = metrics.aggregate(pipeline, {explain: true});
ole.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)


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.