Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 1.43 KB

README.md

File metadata and controls

39 lines (28 loc) · 1.43 KB

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:

    col = new Meteor.Collection "name"

    if Meteor.isServer
        # mapReduce
        map = function() {emit(this.Region, this.Amount);}
        reduce = function(reg, am) { return Array.sum(am);};

        col.mapReduce map, reduce, {out: "out_collection_name", verbose: true}, (err,res)->
            console.dir res.stats # statistics object for running mapReduce
        
        # distinct
        result = col.distinct "Field Name"
        console.dir result

        #aggregate
        result = col.aggregate pipeline
        console.dir result

To install it, run:

$ mrt add mongodb-server-aggregation

You can also perform Mongo's inline mapReduce query by not specifying 'out' option at all or by setting it to out: {inline: 1}. The result must fit within the maximum size of a BSON document (which is 16 megabytes by default).

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