summaryrefslogtreecommitdiff
path: root/jstests/aggregation/large_bson_mid_pipeline.js
blob: 0604bff86c27d303513e7ca7b640a4581421d9f0 (plain)
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
/**
 * 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.
 */
(function() {
"use strict";

load("jstests/libs/analyze_plan.js");  // For 'getAggPlanStage()'.

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());
})();