NotExpression.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var NotExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /**
  4. * An $not pipeline expression.
  5. *
  6. * @see evaluate
  7. * @class NotExpression
  8. * @namespace mungedb.aggregate.pipeline.expressions
  9. * @module mungedb-aggregate
  10. * @constructor
  11. **/
  12. var klass = function NotExpression(){
  13. if(arguments.length !== 0) throw new Error("zero args expected");
  14. base.call(this);
  15. }, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  16. // DEPENDENCIES
  17. var Value = require("../Value");
  18. // PROTOTYPE MEMBERS
  19. proto.getOpName = function getOpName(){
  20. return "$not";
  21. };
  22. proto.addOperand = function addOperand(expr) {
  23. this.checkArgLimit(1);
  24. base.prototype.addOperand.call(this, expr);
  25. };
  26. /**
  27. * Returns the boolean opposite value passed to it. When passed a true value, $not returns false; when passed a false value, $not returns true.
  28. * @method evaluate
  29. **/
  30. proto.evaluate = function evaluate(doc){
  31. this.checkArgCount(1);
  32. var op = this.operands[0].evaluate(doc);
  33. return !Value.coerceToBool(op);
  34. };
  35. return klass;
  36. })();