jstests/sharding/merge_from_stale_mongos.js
// 'mongosList' into a list if it is not an array.
'mongosList' into a list if it is not an array.
' mongosList ' into a list if it is not an array .
function runMergeTest(whenMatchedMode, whenNotMatchedMode, mongosList) {
    if (!(mongosList instanceof Array)) {
        mongosList = [mongosList];
    }
    mongosList.forEach(mongos => {
        targetColl.remove({});
        sourceColl.remove({});
        assert.commandWorked(sourceColl.insert([{_id: -1}, {_id: 0}, {_id: 1}]));
        assert.commandWorked(targetColl.insert([{_id: -2}, {_id: 2}, {_id: 3}]));
        mongos[sourceColl.getName()].aggregate([{
            $merge: {
                into: targetColl.getName(),
                whenMatched: whenMatchedMode,
                whenNotMatched: whenNotMatchedMode
            }
        }]);
        assert.eq(whenNotMatchedMode == "discard" ? 3 : 6, targetColl.find().itcount());
    });
}
function runMergeTest ( whenMatchedMode , whenNotMatchedMode , mongosList ) { if ( ! ( mongosList instanceof Array ) ) { mongosList = [ mongosList ] ; } mongosList . forEach ( mongos => { targetColl . remove ( { } ) ; sourceColl . remove ( { } ) ; assert . commandWorked ( sourceColl . insert ( [ { _id : - 1 } , { _id : 0 } , { _id : 1 } ] ) ) ; assert . commandWorked ( targetColl . insert ( [ { _id : - 2 } , { _id : 2 } , { _id : 3 } ] ) ) ; mongos [ sourceColl . getName ( ) ] . aggregate ( [ { $merge : { into : targetColl . getName ( ) , whenMatched : whenMatchedMode , whenNotMatched : whenNotMatchedMode } } ] ) ; assert . eq ( whenNotMatchedMode == "discard" ? 3 : 6 , targetColl . find ( ) . itcount ( ) ) ; } ) ; }
'mongosList' into a list if it is not an array.
' mongosList ' into a list if it is not an array .
// Insert several documents into the source and target collection without any conflicts. // Note that the chunk split point is at {_id: 0}. // If whenNotMatchedMode is "discard", then the documents in the source collection will // not get written to the target since none of them match.