Aggregator.js 744 B

1234567891011121314151617181920212223242526
  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. return klass;
  23. })();