0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00

SERVER-46997 Test $out, $merge, non-inline mapReduce fail when sent to a secondary with primary read pref

This commit is contained in:
David Storch 2020-04-01 10:27:58 -04:00 committed by Evergreen Agent
parent 526e5bcf9e
commit ee48bf3b43

View File

@ -49,5 +49,26 @@ for (let readMode of ["commands", "legacy"]) {
}
}
function assertNotMasterNoSlaveOk(func) {
secDB.getMongo().forceReadMode("commands");
secDB.getMongo().setSlaveOk(false);
secDB.getMongo().setReadPref("primary");
const res = assert.throws(func);
assert.commandFailedWithCode(res, ErrorCodes.NotMasterNoSlaveOk);
}
// Test that agg with $out/$merge and non-inline mapReduce fail with 'NotMasterNoSlaveOk' when
// directed at a secondary with "primary" read preference.
const secondaryColl = secDB.slaveok_read_pref;
assertNotMasterNoSlaveOk(() => secondaryColl.aggregate([{$out: "target"}]).itcount());
assertNotMasterNoSlaveOk(
() =>
secondaryColl
.aggregate([{$merge: {into: "target", whenMatched: "fail", whenNotMatched: "insert"}}])
.itcount());
assertNotMasterNoSlaveOk(() => secondaryColl.mapReduce(() => emit(this.a),
(k, v) => Array.sum(b),
{out: {replace: "target"}}));
rst.stopSet();
})();
})();