summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorIan Boros <ian.boros@mongodb.com>2019-10-24 18:51:00 +0000
committerevergreen <evergreen@mongodb.com>2019-10-24 18:51:00 +0000
commit6344b4cdc185f2e3438f3f46f35de472820f66a6 (patch)
tree2e370ad7f495426a39a57883e828a3c419a05a96 /jstests
parentce00713876aa3388a2abcebda00672632a0c5ff5 (diff)
downloadmongo-6344b4cdc185f2e3438f3f46f35de472820f66a6.tar.gz
SERVER-7502 test that partial projection of _id works correctly
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/sources/project/remove_redundant_projects.js12
-rw-r--r--jstests/core/id_partial_projection.js21
2 files changed, 28 insertions, 5 deletions
diff --git a/jstests/aggregation/sources/project/remove_redundant_projects.js b/jstests/aggregation/sources/project/remove_redundant_projects.js
index e4584df4f65..ea620be2c2a 100644
--- a/jstests/aggregation/sources/project/remove_redundant_projects.js
+++ b/jstests/aggregation/sources/project/remove_redundant_projects.js
@@ -140,13 +140,15 @@ assertResultsMatch({
removedProjectStage: {_id: 0, a: 1}
});
-// Test that projections on _id with nested fields are not removed from pipeline. Due to
-// SERVER-7502, the dependency analysis does not generate a covered projection for nested
-// fields in _id and thus we cannot remove the stage.
+// Test that projections on _id with nested fields are removed from pipeline.
indexSpec = {
'_id.a': 1,
a: 1
};
-assertResultsMatch(
- {pipeline: [{$project: {'_id.a': 1}}], expectProjectToCoalesce: false, index: indexSpec});
+assertResultsMatch({
+ pipeline: [{$match: {"_id.a": 1}}, {$project: {'_id.a': 1}}],
+ expectProjectToCoalesce: true,
+ index: indexSpec,
+ pipelineOptimizedAway: true,
+});
}());
diff --git a/jstests/core/id_partial_projection.js b/jstests/core/id_partial_projection.js
new file mode 100644
index 00000000000..7affbcfb875
--- /dev/null
+++ b/jstests/core/id_partial_projection.js
@@ -0,0 +1,21 @@
+/**
+ * Tests partial inclusion/exclusion of _id.
+ * See SERVER-7502 for details.
+ */
+(function() {
+"use strict";
+
+const coll = db.id_partial_projection;
+coll.drop();
+
+assert.commandWorked(coll.insert({_id: {a: 1, b: 1}, otherField: 1}));
+assert.commandWorked(coll.insert({_id: 3, otherField: 2}));
+
+assert.eq(coll.find({}, {"_id": 1}).toArray(), [{_id: {a: 1, b: 1}}, {_id: 3}]);
+assert.eq(coll.find({}, {"_id.a": 1}).toArray(), [{_id: {a: 1}}, {}]);
+assert.eq(coll.find({}, {"_id.b": 1}).toArray(), [{_id: {b: 1}}, {}]);
+
+assert.eq(coll.find({}, {"_id.a": 0}).toArray(),
+ [{_id: {b: 1}, otherField: 1}, {_id: 3, otherField: 2}]);
+assert.eq(coll.find({}, {_id: 0}).toArray(), [{otherField: 1}, {otherField: 2}]);
+})();