1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/**
* This test ensures that stages dependent on a let variable optimizing to a constant in a $lookup
* pipeline are evaluated correctly.
* @tags: [assumes_unsharded_collection]
*/
load('jstests/aggregation/extras/utils.js'); // For arrayEq.
load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.
(function() {
"use strict";
const collName = "lookup_let_redact";
const coll = db[collName];
coll.drop();
assert.commandWorked(coll.insert([
{_id: "true", test: true},
{_id: "false", test: false},
]));
const verifyAggregationResults = ({pipeline, expected}) => {
assert(arrayEq(coll.aggregate(pipeline).toArray(), expected, true));
};
// Verify $redact.
verifyAggregationResults({
pipeline: [
{$lookup: {
from: collName,
let: {iShouldPrune: "$test"},
pipeline: [
{$redact: {$cond: {if: "$$iShouldPrune", then: "$$PRUNE", else: "$$DESCEND"}}}
],
as: "redacted"
}}
],
expected: [
{_id: "true", test: true, redacted: []}, // Expect that documents were pruned.
{_id: "false", test: false, redacted: [ // Expect that $redact descended instead.
{_id: "true", test: true},
{_id: "false", test: false}
]}
]
});
}());
|