Browse Source

EAGLESIX-2721: now ours looks more like Mongo's

Jake Delaney 11 years ago
parent
commit
bc1596d251
1 changed files with 18 additions and 6 deletions
  1. 18 6
      lib/pipeline/expressions/ConcatExpression.js

+ 18 - 6
lib/pipeline/expressions/ConcatExpression.js

@@ -29,13 +29,25 @@ proto.getOpName = function getOpName(){
  * @method evaluate
  **/
 proto.evaluateInternal = function evaluateInternal(vars) {
-    return this.operands.map(function(x) {
-		var y = x.evaluateInternal(vars);
-		if(typeof(y) !== "string") {
-	    	throw new Error("$concat only supports strings, not "+typeof(y)+"; code 16702");
+	var n = this.operands.length,
+		result = "";
+
+	for (var i = 0; i < n; ++i){
+
+		var value = this.operands[i].evaluateInternal(vars);
+
+		if (value === null || value === undefined){
+			return null;
 		}
-	return y;
-    }).join("");
+
+		if (typeof value !== "string"){
+			throw new Error("uassert 16702: " + this.getOpName() + " only supports strings, not " + typeof value);
+		}
+
+		result = result.concat(value);
+	}
+
+	return result;
 };
 
 Expression.registerExpression(klass.opName, base.parse);