zvictor:mongodb-server-aggregation

v1.0.4Published 11 years ago

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

mongodb-server-aggregation

Very simple implementation of some of mongodb aggregation framework functions for Meteor.

Mongodb-server-aggregation is a fork of mongodb-aggregation that do not expose the aggregation framework to the client, being available only on server side.

It extends Collection with 3 methods so far, mapReduce, distinct and aggregate, so that you can do:

1    col = new Meteor.Collection "name"
2
3    if Meteor.isServer
4        # mapReduce
5        map = function() {emit(this.Region, this.Amount);}
6        reduce = function(reg, am) { return Array.sum(am);};
7
8        col.mapReduce map, reduce, {out: "out_collection_name", verbose: true}, (err,res)->
9            console.dir res.stats # statistics object for running mapReduce
10        
11        # distinct
12        result = col.distinct "Field Name"
13        console.dir result
14
15        #aggregate
16        result = col.aggregate pipeline
17        console.dir result

To install it, run:

$ mrt add mongodb-server-aggregation

This package is MIT Licensed. Do whatever you like with it but any responsibility for doing so is your own.