|
|
@@ -2,15 +2,15 @@
|
|
|
|
|
|
/**
|
|
|
* Create an expression that returns true exists in any element.
|
|
|
- * @class AnyElementExpression
|
|
|
+ * @class AnyElementTrueExpression
|
|
|
* @namespace mungedb-aggregate.pipeline.expressions
|
|
|
* @module mungedb-aggregate
|
|
|
* @constructor
|
|
|
**/
|
|
|
-var AnyElementExpression = module.exports = function AnyElementExpression(){
|
|
|
+var AnyElementTrueExpression = module.exports = function AnyElementTrueExpression(){
|
|
|
if (arguments.length !== 0) throw new Error("zero args expected");
|
|
|
base.call(this);
|
|
|
-}, klass = AnyElementExpression, NaryExpression = require("./NaryExpression"), base = NaryExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
+}, klass = AnyElementTrueExpression, NaryExpression = require("./NaryExpression"), base = NaryExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
// DEPENDENCIES
|
|
|
var Value = require("../Value"),
|
|
|
@@ -23,19 +23,20 @@ proto.getOpName = function getOpName(){
|
|
|
|
|
|
/**
|
|
|
* Takes an array of one or more numbers and returns true if any.
|
|
|
- * @method @evaluate
|
|
|
+ * @method @evaluateInternal
|
|
|
**/
|
|
|
proto.evaluateInternal = function evaluateInternal(doc) {
|
|
|
|
|
|
- if (!doc instanceof Array) throw new Error("$anyElement requires an array");
|
|
|
+ if (!doc instanceof Array) throw new Error("$anyElementTrue requires an array");
|
|
|
+
|
|
|
var total = 0;
|
|
|
for (var i = 0, n = doc.length; i < n; ++i) {
|
|
|
- var value = doc[i].evaluateInternal(doc);
|
|
|
- if ( value.coerceToDouble() )
|
|
|
+ var value = doc[i].evaluateInternal([i]);
|
|
|
+ if ( value.coerceToBool() )
|
|
|
return true;
|
|
|
}
|
|
|
+ return false;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
/** Register Expression */
|
|
|
-Expression.registerExpression("$anyElement",AnyElementExpression.parse);
|
|
|
+Expression.registerExpression("$anyElementTrue",AnyElementTrueExpression.parse);
|