瀏覽代碼

Merge branch 'feature/mongo_2.6.5_expressions_ObjectExpression' of https://github.com/RiveraGroup/mungedb-aggregate into feature/mongo_2.6.5_expressions_ObjectExpression

Jason Walton 11 年之前
父節點
當前提交
c9eb875390

+ 4 - 3
lib/pipeline/expressions/FieldPathExpression.js

@@ -178,14 +178,15 @@ proto.optimize = function(){
         return this;
 };
 
-proto.addDependencies = function addDependencies(deps){
+proto.addDependencies = function addDependencies(depsTracker){
 	if(this.path.fields[0] === "CURRENT" || this.path.fields[0] === "ROOT") {
 		if(this.path.fields.length === 1) {
-			deps[""] = 1;
+			depsTracker.fields[""] = 1;
 		} else {
-			deps[this.path.tail().getPath(false)] = 1;
+			depsTracker.fields[this.path.tail().getPath(false)] = 1;
 		}
 	}
+    return depsTracker;
 };
 
 // renamed write to get because there are no streams

+ 9 - 6
lib/pipeline/expressions/ObjectExpression.js

@@ -82,14 +82,17 @@ proto.isSimple = function isSimple(){
 	return true;
 };
 
-proto.addDependencies = function addDependencies(deps, path){
+proto.addDependencies = function addDependencies(depsTracker, path){
+	if (typeof depsTracker.fields == 'undefined'){
+		depsTracker.fields = {};
+	}
 	var pathStr = "";
 	if (path instanceof Array) {
 		if (path.length === 0) {
 			// we are in the top level of a projection so _id is implicit
 			if (!this.excludeId) {
-							deps[Document.ID_PROPERTY_NAME] = 1;
-						}
+				depsTracker.fields[Document.ID_PROPERTY_NAME] = 1;
+			}
 		} else {
 			pathStr = new FieldPath(path).getPath() + ".";
 		}
@@ -100,15 +103,15 @@ proto.addDependencies = function addDependencies(deps, path){
 		var expr = this._expressions[key];
 		if (expr !== undefined && expr !== null) {
 			if (path instanceof Array) path.push(key);
-			expr.addDependencies(deps, path);
+			expr.addDependencies(depsTracker, path);
 			if (path instanceof Array) path.pop();
 		} else { // inclusion
 			if (path === undefined || path === null) throw new Error("inclusion not supported in objects nested in $expressions; uassert code 16407");
-			deps[pathStr + key] = 1;
+			depsTracker.fields[pathStr + key] = 1;
 		}
 	}
 
-	return deps;	// NOTE: added to munge as a convenience
+	return depsTracker;	// NOTE: added to munge as a convenience
 };
 
 /**

+ 1 - 0
test/lib/pipeline/expressions/ObjectExpression.js

@@ -37,6 +37,7 @@ function assertExpectedResult(args) {
 	args.expression.addToDocument(result, args.source, variable);
 	assert.deepEqual(result, args.expected);
 	var dependencies = {};
+	debugger
 	args.expression.addDependencies(dependencies, [/*FAKING: includePath=true*/]);
 	//dependencies.sort(), args.expectedDependencies.sort();	// NOTE: this is a minor hack added for munge because I'm pretty sure order doesn't matter for this anyhow
 	assert.deepEqual(Object.keys(dependencies).sort(), Object.keys(args.expectedDependencies).sort());