From e699ae35a04c421398adb76002546da720c25673 Mon Sep 17 00:00:00 2001 From: Ian Boros Date: Thu, 12 Dec 2019 23:41:34 +0000 Subject: SERVER-26066 Fix dependency analysis for projections with expressions on dotted fields --- .../sources/project/project_dotted_paths.js | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 jstests/aggregation/sources/project/project_dotted_paths.js (limited to 'jstests/aggregation') diff --git a/jstests/aggregation/sources/project/project_dotted_paths.js b/jstests/aggregation/sources/project/project_dotted_paths.js new file mode 100644 index 00000000000..cf730861e5e --- /dev/null +++ b/jstests/aggregation/sources/project/project_dotted_paths.js @@ -0,0 +1,26 @@ +// Test that projection of dotted paths which happens in the "agg" layer works correctly. See +// SERVER-26066 for details. +(function() { +const coll = db.project_dotted_paths; +coll.drop(); + +assert.commandWorked(coll.insert({a: [1, {b: 2}, 3, {}]})); + +function checkResultsConsistent(projection, expectedResults) { + const aggResults = coll.aggregate([{$project: projection}]).toArray(); + const aggNoPushdownResults = + coll.aggregate([{$_internalInhibitOptimization: {}}, {$project: projection}]).toArray(); + const findResults = coll.find({}, projection).toArray(); + + assert.eq(aggResults, expectedResults); + assert.eq(aggNoPushdownResults, expectedResults); + assert.eq(findResults, expectedResults); +} + +checkResultsConsistent({"a": {$literal: "newValue"}, _id: 0}, [{a: "newValue"}]); +checkResultsConsistent({"a.b": {$literal: "newValue"}, _id: 0}, + [{a: [{b: "newValue"}, {b: "newValue"}, {b: "newValue"}, {b: "newValue"}]}]); +checkResultsConsistent({"a.b.c": {$literal: "newValue"}, _id: 0}, [ + {a: [{b: {c: "newValue"}}, {b: {c: "newValue"}}, {b: {c: "newValue"}}, {b: {c: "newValue"}}]} +]); +})(); -- cgit v1.2.1