"use strict"; var async = require("async"); var Pipeline = module.exports = (function(){ // CONSTRUCTOR /** * mongodb "commands" (sent via db.$cmd.findOne(...)) subclass to make a command. define a singleton object for it. * @class Pipeline * @namespace mungedb.aggregate.pipeline * @module mungedb-aggregate * @constructor **/ var klass = function Pipeline(/*theCtx*/){ this.sourceVector = [];//should be provate? }, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}}); var LimitDocumentSource = require('./documentSources/LimitDocumentSource'), MatchDocumentSource = require('./documentSources/MatchDocumentSource'), ProjectDocumentSource = require('./documentSources/ProjectDocumentSource'), SkipDocumentSource = require('./documentSources/SkipDocumentSource'), UnwindDocumentSource = require('./documentSources/UnwindDocumentSource'), GroupDocumentSource = require('./documentSources/GroupDocumentSource'), SortDocumentSource = require('./documentSources/SortDocumentSource'); klass.StageDesc = {};//attaching this to the class for test cases klass.StageDesc[LimitDocumentSource.limitName] = LimitDocumentSource.createFromJson; klass.StageDesc[MatchDocumentSource.matchName] = MatchDocumentSource.createFromJson; klass.StageDesc[ProjectDocumentSource.projectName] = ProjectDocumentSource.createFromJson; klass.StageDesc[SkipDocumentSource.skipName] = SkipDocumentSource.createFromJson; klass.StageDesc[UnwindDocumentSource.unwindName] = UnwindDocumentSource.createFromJson; klass.StageDesc[GroupDocumentSource.groupName] = GroupDocumentSource.createFromJson; klass.StageDesc[SortDocumentSource.sortName] = SortDocumentSource.createFromJson; /** * Create a pipeline from the command. * * @static * @method parseCommand * @param {Object} cmdObj the command object sent from the client * @returns {Array} the pipeline, if created, otherwise a NULL reference **/ klass.parseCommand = function parseCommand(docSrcs, pipelineArgs){ //We are require()'ing this here in case the Pipeline class was overriden by someone else. var pipelineInstance = new (require("../Aggregator")).Pipeline(pipelineArgs); //Note: munge: skipping the command parsing since all we care about is the pipeline var sourceVector = pipelineInstance.sourceVector, nSteps = docSrcs.length; for( var iStep = 0; iStep