NotExpression.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. /**
  3. * A $not pipeline expression.
  4. * @see evaluateInternal
  5. * @class NotExpression
  6. * @namespace mungedb-aggregate.pipeline.expressions
  7. * @module mungedb-aggregate
  8. * @constructor
  9. **/
  10. var NotExpression = module.exports = function NotExpression() {
  11. this.nargs = 1;
  12. base.call(this);
  13. }, klass = NotExpression,
  14. base = require("./NaryExpression"),
  15. proto = klass.prototype = Object.create(base.prototype, {
  16. constructor: {
  17. value: klass
  18. }
  19. });
  20. // DEPENDENCIES
  21. var Value = require("../Value"),
  22. Expression = require("./Expression");
  23. // PROTOTYPE MEMBERS
  24. proto.getOpName = function getOpName() {
  25. return "$not";
  26. };
  27. /**
  28. * Returns the boolean opposite value passed to it. When passed a true value, $not returns false; when passed a false value, $not returns true.
  29. * @method evaluateInternal
  30. **/
  31. proto.evaluateInternal = function evaluateInternal(vars) {
  32. var op = this.operands[0].evaluateInternal(vars);
  33. return !Value.coerceToBool(op);
  34. };
  35. /** Register Expression */
  36. Expression.registerExpression("$not", base.parse(NotExpression));