PipelineCommand.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var PipelineCommand = module.exports = (function(){
  2. // CONSTRUCTOR
  3. var klass = function PipelineCommand(cmdObj){
  4. /* try to parse the command; if this fails, then we didn't run */
  5. //NOTE: this is different from the mongo implementation. It used to be in the 'run' method that we would parse the pipeline,
  6. //but we decided it would be better to be able to save the parsed command
  7. this.pPipeline = Pipeline.parseCommand(cmdObj);
  8. }, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  9. var Pipeline = require('../pipeline/Pipeline'),
  10. PipelineD = require('../pipeline/PipelineD');
  11. /**
  12. * Execute the pipeline.
  13. **/
  14. proto.executePipeline = function executePipeline(result, pPipeline, pSource){
  15. return pPipeline.run(result, pSource);
  16. };
  17. /**
  18. * Documents are retrieved until the
  19. * cursor is exhausted (or another termination condition occurs).
  20. **/
  21. proto.runExecute = function runExecute(result, db){
  22. var pSource = PipelineD.prepareCursorSource(this.pPipeline, db);
  23. return this.executePipeline(result, this.pPipeline, pSource);
  24. };
  25. /**
  26. * run the command
  27. **/
  28. proto.run = function run(db, result){
  29. if (!this.pPipeline){
  30. return false;
  31. }
  32. return this.runExecute(result, db);
  33. };
  34. return klass;
  35. })();