Files
mongo/jstests/sharding/query/map_reduce/mr_noscripting.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

40 lines
1.1 KiB
JavaScript

// Tests that running mapReduce does not crash anything if the shards have scripting disabled.
import {ShardingTest} from "jstests/libs/shardingtest.js";
const shardOpts = [
{noscripting: ""},
{}, // just use default params
];
const st = new ShardingTest({shards: shardOpts});
const mongos = st.s;
const testDB = mongos.getDB("test");
const coll = testDB.bar;
// Shard the collection and make sure there is a non-empty chunk on each shard.
st.shardColl(coll.getName(), {x: 1}, {x: 0}, {x: 1});
assert.commandWorked(coll.insert([{x: 1}, {x: -1}]));
const mapFn = function () {
emit(this.x, 1);
};
const reduceFn = function (key, values) {
return 1;
};
const mrCmd = {
mapreduce: "bar",
map: mapFn,
reduce: reduceFn,
out: {inline: 1},
};
// If the command succeeds when it should have failed, having the explain plan in the log may help.
assert.commandFailedWithCode(testDB.runCommand(mrCmd), 31264, () => {
const explain = tojson(testDB.runCommand({explain: mrCmd}));
return `mapReduce command was expected to fail, but succeeded; explain plan is ${explain}`;
});
st.stop();