(function() {
"use strict";
const memoryLimitMb = 1;
const memoryLimitBytes = memoryLimitMb * 1024 * 1024;
const conn = MongoRunner.runMongod({
setParameter: {
internalDocumentSourceGroupMaxMemoryBytes: memoryLimitBytes,
internalQuerySlotBasedExecutionHashAggApproxMemoryUseInBytesBeforeSpill: memoryLimitBytes
}
});
const testDb = conn.getDB(jsTestName());
testDb.largeColl.drop();
const largeStr = "A".repeat(1024 * 1024); for (let i = 0; i < memoryLimitMb + 1; ++i)
assert.commandWorked(testDb.largeColl.insert({x: i, largeStr: largeStr + i}));
const pipeline = [{$group: {_id: '$largeStr', minId: {$min: '$_id'}}}];
assert.throwsWithCode(() => testDb.largeColl.aggregate(pipeline, {allowDiskUse: false}),
ErrorCodes.QueryExceededMemoryLimitNoDiskUseAllowed);
testDb.largeColl.aggregate(pipeline);
MongoRunner.stopMongod(conn);
})();