Files
mongo/jstests/aggregation/sources/redact/root_redact.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

27 lines
655 B
JavaScript

// Usage of $$ROOT variable can lead to Document cache reallocation and possible memory corruption.
// Test is checking that this is not the case.
const bigStr = "X".repeat(1024);
const doc = {
_id: 0,
d: true,
sub: {d: false, str: bigStr},
str: bigStr,
};
db.test.drop();
assert.commandWorked(db.test.insertOne(doc));
const pipeline = [
{
$redact: {
$cond: {
if: "$d",
then: "$$DESCEND",
else: {$cond: {if: {$objectToArray: "$$ROOT"}, then: "$$KEEP", else: "$$PRUNE"}},
},
},
},
];
assert.eq([doc], db.test.aggregate(pipeline).toArray());