PushAccumulator.js 836 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. /**
  3. * Constructor for PushAccumulator. Pushes items onto an array.
  4. * @class PushAccumulator
  5. * @namespace mungedb-aggregate.pipeline.accumulators
  6. * @module mungedb-aggregate
  7. * @constructor
  8. **/
  9. var PushAccumulator = module.exports = function PushAccumulator(){
  10. this.values = [];
  11. base.call(this);
  12. }, klass = PushAccumulator, Accumulator = require("./Accumulator"), base = Accumulator, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  13. proto.evaluate = function evaluate(doc){
  14. if (this.operands.length != 1) throw new Error("this should never happen");
  15. var v = this.operands[0].evaluate(doc);
  16. if (v !== undefined) this.values.push(v);
  17. return null;
  18. };
  19. proto.getValue = function getValue(){
  20. return this.values;
  21. };
  22. proto.getOpName = function getOpName(){
  23. return "$push";
  24. };