SetEqualsExpression.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. /**
  3. * A $setequals pipeline expression.
  4. * @see evaluateInternal
  5. * @class SetEqualsExpression
  6. * @namespace mungedb-aggregate.pipeline.expressions
  7. * @module mungedb-aggregate
  8. * @constructor
  9. **/
  10. var SetEqualsExpression = module.exports = function SetEqualsExpression() {
  11. base.call(this);
  12. }, klass = SetEqualsExpression, base = require("./NaryBaseExpressionT")(SetEqualsExpression), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  13. // DEPENDENCIES
  14. var Value = require("../Value"),
  15. Expression = require("./Expression");
  16. // PROTOTYPE MEMBERS
  17. proto.getOpName = function getOpName() {
  18. return "$setequals";
  19. };
  20. /**
  21. * Takes 2 arrays. Assigns the second array to the first array.
  22. * @method evaluateInternal
  23. **/
  24. proto.evaluateInternal = function evaluateInternal(vars) {
  25. var array1 = this.operands[0].evaluateInternal(vars),
  26. array2 = this.operands[1].evaluateInternal(vars);
  27. if (array1 instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an array");
  28. if (array2 instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an array");
  29. array1 = array2;
  30. return array1;
  31. };
  32. /** Register Expression */
  33. Expression.registerExpression("$setequals", base.parse);