"use strict"; /** * A $subtract pipeline expression. * @see evaluateInternal * @class SubtractExpression * @namespace mungedb-aggregate.pipeline.expressions * @module mungedb-aggregate * @constructor **/ var SubtractExpression = module.exports = function SubtractExpression() { this.fixedAirty(2); if (arguments.length !== 0) throw new Error("zero args expected"); base.call(this); }, klass = SubtractExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, { constructor: { value: klass } }); // DEPENDENCIES var Value = require("../Value"), Expression = require("./Expression"); // PROTOTYPE MEMBERS proto.getOpName = function getOpName() { return "$subtract"; }; /** * Takes an array that contains a pair of numbers and subtracts the second from the first, returning their difference. **/ proto.evaluateInternal = function evaluateInternal(doc) { this.checkArgCount(2); var left = this.operands[0].evaluateInternal(doc), right = this.operands[1].evaluateInternal(doc); if (left instanceof Date || right instanceof Date) throw new Error("$subtract does not support dates; code 16376"); return left - right; }; /** Register Expression */ Expression.registerExpression("$subtract", SubtractExpression.parse);