Files
mongo/jstests/aggregation/sources/group/group_by_system_variable.js
Zack Winter e2d43f0b28 SERVER-100116 Swap eslint to rules_lint & upgrade to 9.19.0 (#31917)
GitOrigin-RevId: d08518aa13c42c1dfdb68fbbd74d9898b2f09bdf
2025-04-09 20:14:48 +00:00

32 lines
940 B
JavaScript

const coll = db[jsTestName()];
coll.drop();
assert.commandWorked(coll.insert({_id: 1, x: 1}));
/*
* Tests that the server doesn't crash when you group by a system variable.
* Reproduces SERVER-57164.
*/
function testAggWithSystemVariable(varName, explain) {
try {
// This query might or might not throw depending on the engine used
// and whether the variable is defined.
if (explain) {
coll.explain().aggregate({$group: {_id: varName}});
} else {
coll.aggregate({$group: {_id: varName}});
}
} catch (e) {
} finally {
// Make sure the server didn't crash.
db.hello();
}
}
testAggWithSystemVariable("$$IS_MR", true);
testAggWithSystemVariable("$$JS_SCOPE", true);
testAggWithSystemVariable("$$CLUSTER_TIME", true);
testAggWithSystemVariable("$$IS_MR");
testAggWithSystemVariable("$$JS_SCOPE");
testAggWithSystemVariable("$$CLUSTER_TIME");