summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorIan Boros <ian.boros@mongodb.com>2019-11-12 23:31:43 +0000
committerevergreen <evergreen@mongodb.com>2019-11-12 23:31:43 +0000
commit05f45f9a3f3deb4e5d1e3e1f2ab1e4a2b80e959e (patch)
treedce18cff88d6d541432a940987bbede056eb6d57 /jstests/aggregation
parent812524322f9f947ca2198366f9802b8befe3274d (diff)
downloadmongo-05f45f9a3f3deb4e5d1e3e1f2ab1e4a2b80e959e.tar.gz
SERVER-44321 treat $meta-only projections depending on context
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/sources/project/id_meta_projection.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/jstests/aggregation/sources/project/id_meta_projection.js b/jstests/aggregation/sources/project/id_meta_projection.js
new file mode 100644
index 00000000000..1a7b653b9c1
--- /dev/null
+++ b/jstests/aggregation/sources/project/id_meta_projection.js
@@ -0,0 +1,22 @@
+(function() {
+"use strict";
+
+const coll = db.id_meta_projection;
+coll.drop();
+
+assert.commandWorked(coll.insert({_id: 0, a: 1, b: 1}));
+
+// Run the aggregate once where the $project can be pushed down.
+const projectPushedDownRes =
+ coll.aggregate([{$sort: {a: 1}}, {$project: {_id: 0, metaField: {$meta: "sortKey"}}}])
+ .toArray();
+
+// Run it again where it cannot be pushed down.
+const projectNotPushedDownRes = coll.aggregate([
+ {$sort: {a: 1}},
+ {$_internalInhibitOptimization: {}},
+ {$project: {_id: 0, metaField: {$meta: "sortKey"}}}
+ ])
+ .toArray();
+assert.eq(projectPushedDownRes, projectNotPushedDownRes);
+})();