summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2022-05-31 09:24:58 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-18 20:37:08 +0000
commit39a79c12b930b7adc5fe2872e482f9e483121dcf (patch)
treef5ca4862c6d23bbfd62cb119b780dffa31bb86a9 /jstests
parent65002ae2d4bacf9413383faa4b38d3480a2a8328 (diff)
downloadmongo-39a79c12b930b7adc5fe2872e482f9e483121dcf.tar.gz
SERVER-63845 Separate variable reference tracking from pipeline field dependency analysis
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js b/jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js
index 7235bd67410..c5a4c80e674 100644
--- a/jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js
+++ b/jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js
@@ -7,6 +7,9 @@
(function() {
"use strict";
+load("jstests/libs/fixture_helpers.js"); // For isSharded.
+load("jstests/aggregation/extras/utils.js"); // for arrayEq
+
const testColl = db.lookup_non_correlated_prefix;
testColl.drop();
const joinColl = db.lookup_non_correlated_prefix_join;
@@ -77,6 +80,39 @@ cursor.toArray().forEach(user => {
assert.eq(user['_id'], joinedDocs[0].owner);
});
+// Test for a non-correlated prefix followed by a $facet pipeline that contains a correlated
+// variable reference.
+cursor = testColl.aggregate([
+ {
+ $lookup: {
+ as: 'items_check',
+ from: joinColl.getName(),
+ let : {id: '$_id'},
+ pipeline: [
+ {$match: {owner: "user_1"}},
+ {
+ $facet: {
+ all: [{
+ $redact: {
+ $cond:
+ {if: {$eq: ["$$id", "user_1"]}, then: "$$KEEP", else: "$$PRUNE"}
+ }
+ }],
+ },
+ },
+ ],
+ },
+ },
+]);
+res = cursor.toArray();
+assert(
+ arrayEq(res,
+ [
+ {"_id": "user_1", "items_check": [{"all": [{"_id": "item_1", "owner": "user_1"}]}]},
+ {"_id": "user_2", "items_check": [{"all": []}]}
+ ]),
+ res);
+
// SERVER-57000: Test handling of lack of correlation (addFields with empty set of columns)
assert.doesNotThrow(() => testColl.aggregate([
{