diff options
author | Nicholas Zolnierz <nicholas.zolnierz@mongodb.com> | 2022-05-31 09:24:58 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-18 20:37:08 +0000 |
commit | 39a79c12b930b7adc5fe2872e482f9e483121dcf (patch) | |
tree | f5ca4862c6d23bbfd62cb119b780dffa31bb86a9 /jstests | |
parent | 65002ae2d4bacf9413383faa4b38d3480a2a8328 (diff) | |
download | mongo-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.js | 36 |
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([ { |