diff options
Diffstat (limited to 'jstests/sharding/merge_to_non_existing.js')
-rw-r--r-- | jstests/sharding/merge_to_non_existing.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/jstests/sharding/merge_to_non_existing.js b/jstests/sharding/merge_to_non_existing.js index 585428fcde6..5aad5e003ab 100644 --- a/jstests/sharding/merge_to_non_existing.js +++ b/jstests/sharding/merge_to_non_existing.js @@ -35,12 +35,35 @@ $merge: { into: {db: targetColl.getDB().getName(), coll: targetColl.getName()}, whenMatched: whenMatchedMode, - whenNotMatched: whenNotMatchedMode + whenNotMatched: whenNotMatchedMode, + on: "_id" } }]); assert.eq(whenNotMatchedMode == "discard" ? 0 : 10, targetColl.find().itcount()); }); + // Test that $merge fails if the "on" field is anything but "_id" when the target collection + // does not exist. + 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 assertion below to trip. + if (whenMatchedMode == "fail" || whenNotMatchedMode == "fail") + return; + + targetColl.drop(); + assertErrorCode( + sourceColl, + [{ + $merge: { + into: {db: targetColl.getDB().getName(), coll: targetColl.getName()}, + whenMatched: whenMatchedMode, + whenNotMatched: whenNotMatchedMode, + on: "not_allowed" + } + }], + 51190); + }); + // If 'targetColl' is in the same database as 'sourceColl', test that the legacy $out works // correctly. if (targetColl.getDB() == sourceColl.getDB()) { |