Files
mongo/jstests/aggregation/sources/redact/root_redact.js
Ivan Fefer 1bdaad8b05 SERVER-91339 Load redacted document into cache to avoid cache reallocation (#23244)
GitOrigin-RevId: eea3eadada403cb53bed26fa42104126b5ca7181
2024-06-13 12:01:26 +00:00

25 lines
613 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());