|
|
@@ -2,37 +2,43 @@
|
|
|
|
|
|
/**
|
|
|
* A $subtract pipeline expression.
|
|
|
- * @see evaluate
|
|
|
+ * @see evaluateInternal
|
|
|
* @class SubtractExpression
|
|
|
* @namespace mungedb-aggregate.pipeline.expressions
|
|
|
* @module mungedb-aggregate
|
|
|
* @constructor
|
|
|
**/
|
|
|
-var SubtractExpression = module.exports = function SubtractExpression(){
|
|
|
- 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}});
|
|
|
+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");
|
|
|
+var Value = require("../Value"),
|
|
|
+ Expression = require("./Expression");
|
|
|
|
|
|
// PROTOTYPE MEMBERS
|
|
|
-proto.getOpName = function getOpName(){
|
|
|
- return "$subtract";
|
|
|
-};
|
|
|
-
|
|
|
-proto.addOperand = function addOperand(expr) {
|
|
|
- this.checkArgLimit(2);
|
|
|
- base.prototype.addOperand.call(this, expr);
|
|
|
+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.evaluate = function evaluate(doc) {
|
|
|
- this.checkArgCount(2);
|
|
|
- var left = this.operands[0].evaluate(doc),
|
|
|
- right = this.operands[1].evaluate(doc);
|
|
|
- if (left instanceof Date || right instanceof Date) throw new Error("$subtract does not support dates; code 16376");
|
|
|
- return left - right;
|
|
|
+ * 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);
|