mongo/jstests/aggregation/exec/large_bson_mid_pipeline.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

22 lines
839 B
JavaScript

/**
* Tests that extra-large BSON objects (>16MB) can be materialized for the '$match' stage in the
* middle of the query plan without throwing 'BSONObjectTooLarge' exception.
*/
const testDB = db.getSiblingDB("jsTestName");
assert.commandWorked(testDB.dropDatabase());
const coll = testDB.coll;
const largeString = "x".repeat(10 * 1024 * 1024);
assert.commandWorked(coll.insert({a: 1, b: largeString}));
// Use '$addFields' to create extra-large documents in the middle of the pipeline followed by
// '$match'. Use '$_internalInhibitOptimization' to ensure '$match' is not removed by the optimizer.
const pipeline = [
{$_internalInhibitOptimization: {}},
{$addFields: {c: {$concat: ["$b", "-"]}}},
{$match: {c: {$exists: true}}},
{$project: {a: 1}},
];
assert.doesNotThrow(() => coll.aggregate(pipeline).toArray());