Aggregator.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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(ops){
  6. if (!ops){
  7. throw new Error("mungedb Aggregator requires a pipeline!");
  8. }
  9. if (typeof ops.length !== "number"){
  10. ops = [ops];
  11. }
  12. this.pipeline = new PipelineCommand(ops);
  13. };
  14. proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  15. // PROTOTYPE MEMBERS
  16. proto.execute = function execute(inputs){
  17. var result = {};
  18. result.ok = this.pipeline.run(inputs, result);
  19. //return result; //TODO: figure out if we want mongo style result or a simpler one.
  20. return result.result;
  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. })();