LastAccumulator.js 815 B

12345678910111213141516171819202122232425262728293031
  1. var LastAccumulator = module.exports = (function(){
  2. // Constructor
  3. /**
  4. * Constructor for LastAccumulator, wraps SingleValueAccumulator's constructor and
  5. * finds the last document
  6. *
  7. * @class LastAccumulator
  8. * @namespace munge.pipeline.accumulators
  9. * @module munge
  10. * @constructor
  11. **/
  12. var klass = module.exports = function LastAccumulator(){
  13. base.call(this);
  14. }, SingleValueAccumulator = require("./SingleValueAccumulator"), base = SingleValueAccumulator, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  15. proto.evaluate = function evaluate(doc){
  16. if(this.operands.length != 1) throw new Error("this should never happen");
  17. this.value = this.operands[0].evaluate(doc);
  18. };
  19. proto.getOpName = function getOpName(){
  20. return "$last";
  21. };
  22. return klass;
  23. })();