LastAccumulator.js 778 B

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