A JavaScript data aggregation pipeline based on the MongoDB database's aggregation framework. https://riveragroup.github.io/mungedb-aggregate/

Kyle P Davis 3eaf268a0b Merge branch 'feature/mongo_2.6.5' of https://github.com/RiveraGroup/mungedb-aggregate into feature/mongo_2.6.5 %!s(int64=10) %!d(string=hai) anos
lib 526ddf29fa EAGLESIX-5075: fix stack overflow in async due to some unintentionally deeply recursive sync code %!s(int64=10) %!d(string=hai) anos
npm_scripts fbeb467c04 EAGLESIX-3157: fix npm test to use mocha.opts %!s(int64=11) %!d(string=hai) anos
test 526ddf29fa EAGLESIX-5075: fix stack overflow in async due to some unintentionally deeply recursive sync code %!s(int64=10) %!d(string=hai) anos
.gitignore 3a3cc10b7c add .c9/ to git ignores list %!s(int64=10) %!d(string=hai) anos
.jscheckstyleignore 33a99df088 Fixes #1612, #963: Renamed `alter` to `munge`. Removed unused `microdb`. Added test for `ExpressionDayOfMonth`. Fixed bug calling base `DayOfMonthExpression#addOperand()`. Fixed off-by-one bug in `DayOfMonthExpression#evaluate()`. %!s(int64=12) %!d(string=hai) anos
.jshintrc 8f1b7def78 EAGLESIX-3157: jshint change to abuse expressions %!s(int64=11) %!d(string=hai) anos
NOTES.md 004b6f5755 clean up docs a bit %!s(int64=11) %!d(string=hai) anos
README.md 004b6f5755 clean up docs a bit %!s(int64=11) %!d(string=hai) anos
TODO.md 004b6f5755 clean up docs a bit %!s(int64=11) %!d(string=hai) anos
mungedb-aggregate.js e382544f4e Refs #1879: Fixed jshint and pkg rename issues %!s(int64=12) %!d(string=hai) anos
package.json e5f124cb0e Merge branch 'master' into feature/mongo_2.6.5 %!s(int64=10) %!d(string=hai) anos

README.md

mungedb-aggregate

A JavaScript data aggregation pipeline based on the MongoDB database's aggregation framework.

Based on the MongoDB C++ code (v2.4.0).

Updating to v2.6 soon.

Why

MongoDB Aggregation and JavaScript are both awesome. We put them together.

Now, with the ease of JavaScript and the power of the MongoDB aggregation pipeline, we can provide a single API for data munging, regardless of where execution occurs. You can extend the base functionality to suit your needs.

Example

var aggregate = require("mungedb-aggregate");

var inputs = [
  {v: 1},
  {v: 2},
  {v: 3},
  {v: 4},
  {v: 5}
];

var pipeline = [
  {$match:{
    v: {$gte: 3}
  }},
  {$project:{
    v2: {$multiply: ["$v", "$v"]}
  }}
];

aggregate(pipeline, inputs);  // => [{v2:9}, {v2:16}, {v2:25}]

API

Public parts:

  • aggregate(pipeline, [inputs], [callback]) - The data aggregator
    • pipeline - The aggregation pipeline to apply to inputs
    • [inputs] - The input Objects to aggregate or return curried if omitted
    • [callback] - The callback if needed (for extensions using async calls)
  • version - The MongoDB version that this code represents
  • gitVersion - The MongoDB git revision that this code represents

Inner workings:

  • Cursor - Used to go thru data (by PipelineD and CursorDocumentSource)
  • pipeline
    • Pipeline - The pipeline handler
    • PipelineD - The pipeline data reader helper
    • FieldPath - Represents a path to a field within a document
    • Document - Document helpers used throughout the code
    • Value - Value helpers used throughout the code
    • accumulators - The Accumulator classes (used in $group)
    • documentSources - The DocumentSource classes (upper pipeline objects)
    • expressions - The Expression classes (used in $project)