|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
/**
|
|
|
* A $divide pipeline expression.
|
|
|
- * @see evaluate
|
|
|
+ * @see evaluateInternal
|
|
|
* @class DivideExpression
|
|
|
* @namespace mungedb-aggregate.pipeline.expressions
|
|
|
* @module mungedb-aggregate
|
|
|
@@ -14,29 +14,28 @@ var DivideExpression = module.exports = function DivideExpression(){
|
|
|
}, klass = DivideExpression, 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(){ //TODO: try to move this to a static and/or instance field instead of a getter function
|
|
|
return "$divide";
|
|
|
};
|
|
|
|
|
|
-proto.addOperand = function addOperand(expr){
|
|
|
- this.checkArgLimit(2);
|
|
|
- base.prototype.addOperand.call(this, expr);
|
|
|
-};
|
|
|
-
|
|
|
/**
|
|
|
* Takes an array that contains a pair of numbers and returns the value of the first number divided by the second number.
|
|
|
- * @method evaluate
|
|
|
+ * @method evaluateInternal
|
|
|
**/
|
|
|
-proto.evaluate = function evaluate(doc) {
|
|
|
+proto.evaluateInternal = function evaluateInternal(doc) {
|
|
|
this.checkArgCount(2);
|
|
|
- var left = this.operands[0].evaluate(doc),
|
|
|
- right = this.operands[1].evaluate(doc);
|
|
|
+ var left = this.operands[0].evaluateInternal(doc),
|
|
|
+ right = this.operands[1].evaluateInternal(doc);
|
|
|
if (!(left instanceof Date) && (!right instanceof Date)) throw new Error("$divide does not support dates; code 16373");
|
|
|
right = Value.coerceToDouble(right);
|
|
|
if (right === 0) return undefined;
|
|
|
left = Value.coerceToDouble(left);
|
|
|
return left / right;
|
|
|
};
|
|
|
+
|
|
|
+/** Register Expression */
|
|
|
+Expression.registerExpression("$divide",DivideExpression.parse);
|