Files
mongo/jstests/aggregation/accumulators/group_doing_merge_array.js
Alexander Ignatyev 1390ed2b8c SERVER-99616 Make sure that accumulator functions behave in merging pass (#34799)
GitOrigin-RevId: f8492f1958f2d63f63a23ac7b768bbaa7c33a64e
2025-04-10 12:51:37 +00:00

46 lines
1.5 KiB
JavaScript

/**
* The `$doingMerge` parameter of the `$group` stage is intended to be an internal parameter. Since
* we cannot reliably enforce its internal status when authorization is disabled, it is necessary to
* ensure that the accumulator functions behave correctly, even when used within a $group stage with
* $doingMerge: true.
* This suits tests array accumulator functions which were enabled for $group
* in 8.1. TODO SERVER-97514: Once featureFlagArrayAccumulators is removed the tests can be moved to
* the main file: group_doing_merge.js.
*
* @tags: [
* requires_fcv_81,
* featureFlagArrayAccumulators,
* ]
*/
const coll = db[jsTestName()];
coll.drop();
const docs = [
{groupKey: 1, array: [1, 2, 3]},
{groupKey: 1, array: [11, 12, 13]},
{groupKey: 1, array: [21, 22, 23]},
{groupKey: 2, array: [31, 32, 33]},
{groupKey: 2, array: [41, 42, 43]},
{groupKey: 2, array: [51, 52, 53]},
];
assert.commandWorked(coll.insertMany(docs));
function assertNoError(aggFunction, aggFunctionArgument) {
const pipeline = [{
$group: {
_id: "$groupKey",
agg: {[aggFunction]: aggFunctionArgument},
$doingMerge: true,
}
}];
assert.eq(coll.aggregate(pipeline).toArray().length, 2);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Array accumulator functions do not display errors since they already take their inputs as arrays.
assertNoError("$concatArrays", "$array");
assertNoError("$setUnion", "$array");