diff options
author | Nicholas Zolnierz <nicholas.zolnierz@mongodb.com> | 2022-07-25 13:04:05 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-26 14:59:37 +0000 |
commit | 80349ba179b6f87f78d5a9f787ec8848dbd4cc22 (patch) | |
tree | a1a65bf92c316750b0b7e0084538d65e46195d46 /jstests/aggregation | |
parent | 254925ef996e437cd6324e6a2e042d52d4b3761b (diff) | |
download | mongo-80349ba179b6f87f78d5a9f787ec8848dbd4cc22.tar.gz |
SERVER-66548 Add support for dependency tracking to $redact
(cherry picked from commit cc4968771221658d66ff42ed2fb861656c5683ca)
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js | 35 |
1 files changed, 35 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 b4feed0ab31..d377d1016cc 100644 --- a/jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js +++ b/jstests/aggregation/sources/lookup/lookup_non_correlated_prefix.js @@ -8,6 +8,8 @@ (function() { "use strict"; +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; @@ -78,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([ { |