Aggregator.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. var PipelineCommand = require('./commands/PipelineCommand');
  3. var Aggregator = module.exports = (function(){
  4. // CONSTRUCTOR
  5. var base = Object, proto, klass = function Aggregator(docSrcs, pipelineArgs){
  6. if (!docSrcs){
  7. throw new Error("mungedb Aggregator requires a pipeline!");
  8. }
  9. if (typeof docSrcs.length !== "number"){
  10. docSrcs = [docSrcs];
  11. }
  12. this.pipeline = new PipelineCommand(docSrcs, pipelineArgs);
  13. };
  14. proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  15. // PROTOTYPE MEMBERS
  16. proto.execute = function execute(inputs, callback){
  17. this.pipeline.run(inputs,function(err, output){
  18. if (err) return callback(err);
  19. return callback(null, output.result);
  20. });
  21. };
  22. //Expose these so that mungedb-aggregate can be extended.
  23. klass.Pipeline = require("./pipeline/Pipeline");
  24. klass.accumulators = require("./pipeline/accumulators");
  25. klass.documentSources = require("./pipeline/documentSources");
  26. klass.expressions = require("./pipeline/expressions");
  27. klass.commands = require("./commands");
  28. klass.Cursor = require("./Cursor");
  29. return klass;
  30. })();