diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2020-02-13 16:38:33 -0500 |
---|---|---|
committer | Gregory Noma <gregory.noma@gmail.com> | 2020-02-18 17:13:19 -0500 |
commit | a68508f9922ad163ff98f8fa13953b1efe9d57d0 (patch) | |
tree | 1ead40c94d7da611cbb6cd36a342cf76ffe2e452 /jstests/noPassthrough/merge_on_secondary.js | |
parent | 11640b2138d40777a4b45005628b4facfba7e6b2 (diff) | |
download | mongo-46137.tar.gz |
SERVER-46137 Implement ReplicaSetNodeProcessInterface methods needed for $merge46137
Diffstat (limited to 'jstests/noPassthrough/merge_on_secondary.js')
-rw-r--r-- | jstests/noPassthrough/merge_on_secondary.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/jstests/noPassthrough/merge_on_secondary.js b/jstests/noPassthrough/merge_on_secondary.js new file mode 100644 index 00000000000..94ecd8cc232 --- /dev/null +++ b/jstests/noPassthrough/merge_on_secondary.js @@ -0,0 +1,48 @@ +/** + * Tests the behavior of $merge being run on a secondary. + * + * @tags: [assumes_unsharded_collection, requires_replication, requires_spawning_own_processes] + */ +(function() { +"use strict"; + +load("jstests/aggregation/extras/merge_helpers.js"); // For withEachMergeMode. + +let replTest = new ReplSetTest({nodes: 2}); +replTest.startSet(); +replTest.initiate(); +replTest.awaitReplication(); + +let primary = replTest.getPrimary().getDB('test'); +let secondary = replTest.getSecondary().getDB('test'); +secondary.setSlaveOk(true); + +const collPrimary = primary.getCollection('coll'); +const collSecondary = secondary.getCollection('coll'); +const outColl = primary.getCollection('outColl'); + +assert.commandWorked(collPrimary.insert({_id: 0, a: 1}, {writeConcern: {w: 2}})); +assert.commandWorked(collPrimary.insert({_id: 1, a: 2}, {writeConcern: {w: 2}})); + +// Make sure the $merge succeeds without any duplicate keys. +withEachMergeMode(({whenMatchedMode, whenNotMatchedMode}) => { + // Skip the combination of merge modes which will fail depending on the contents of the + // source and target collection, as this will cause the aggregation to fail. + if (whenMatchedMode == "fail" || whenNotMatchedMode == "fail") { + return; + } + + collSecondary.aggregate([{ + $merge: { + into: outColl.getName(), + whenMatched: whenMatchedMode, + whenNotMatched: whenNotMatchedMode + } + }]); + + assert.eq(whenNotMatchedMode == "discard" ? 0 : 2, outColl.find().itcount()); + outColl.drop(); +}); + +replTest.stopSet(); +})();
\ No newline at end of file |