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.
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.
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}]
Public parts:
aggregate(pipeline, [inputs], [callback])
- The data aggregator
pipeline
- The aggregation pipeline to apply toinputs
[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 representsgitVersion
- The MongoDB git revision that this code represents
Inner workings:
Cursor
- Used to go thru data (byPipelineD
andCursorDocumentSource
)pipeline
Pipeline
- The pipeline handlerPipelineD
- The pipeline data reader helperFieldPath
- Represents a path to a field within a documentDocument
- Document helpers used throughout the codeValue
- Value helpers used throughout the codeaccumulators
- TheAccumulator
classes (used in$group
)documentSources
- TheDocumentSource
classes (upper pipeline objects)expressions
- TheExpression
classes (used in$project
)