LastAccumulator.js 910 B

123456789101112131415161718192021222324252627282930313233
  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. this.value = undefined;
  12. }, klass = LastAccumulator, base = require("./Accumulator"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  13. proto.processInternal = function processInternal(input, merging){
  14. this.value = input;
  15. };
  16. proto.getFactory = function getFactory(){
  17. return klass; // using the ctor rather than a separate .create() method
  18. };
  19. proto.getValue = function getValue() {
  20. return this.value;
  21. };
  22. proto.getOpName = function getOpName(){
  23. return "$last";
  24. };
  25. proto.reset = function reset() {
  26. this.value = undefined;
  27. };