The test spawns a parallel shell with the following jstest code evaluated as a --eval argument. (Note the excessive quote escaping is due to this code itself being a string.)
TestData = {
\"minPort\" : 20020,
\"maxPort\" : 20249,
\"peerPids\" : [ ],
\"alwaysUseLogFiles\" : false,
\"failIfUnterminatedProcesses\" : true,
\"isMainTest\" : true,
\"numTestClients\" : 1,
\"backupOnRestartDir\" : null,
\"enableMajorityReadConcern\" : true,
\"mixedBinVersions\" : \"\",
\"noJournal\" : false,
\"storageEngine\" : \"wiredTiger\",
\"storageEngineCacheSizeGB\" : \"1\",
\"testName\" : \"merge_stale_on_fields\",
\"transportLayer\" : \"\",
\"wiredTigerCollectionConfigString\" : \"\",
\"wiredTigerEngineConfigString\" : \"\",
\"wiredTigerIndexConfigString\" : \"\",
\"inEvergreen\" : true,
\"setParameters\" : {
\"featureFlagSBE\" : \"true\",
\"featureFlagTimeseriesCollection\" : \"true\",
\"logComponentVerbosity\" : {
\"replication\" : {
\"election\" : 4,
\"heartbeats\" : 2,
\"initialSync\" : 2,
\"rollback\" : 2
},
\"sharding\" : {
\"migration\" : 2
},
\"storage\" : {
\"recovery\" : 2
},
\"transaction\" : 4,
\"tenantMigration\" : 4
},
\"reshardingMinimumOperationDurationMillis\" : 5000
},
\"setParametersMongos\" : {
\"featureFlagSBE\" : \"true\",
\"featureFlagTimeseriesCollection\" : \"true\",
\"logComponentVerbosity\" : {
\"transaction\" : 3
}
},
\"setParametersMongocryptd\" : {
},
\"undoRecorderPath\" : null,
\"transactionLifetimeLimitSeconds\" : 86400,
\"traceExceptions\" : undefined
};
const source = db.getSiblingDB(\"merge_stale_unique_key\").source;
const error = assert.throws(() => source.aggregate([
{$addFields: {sk: \"$_id\"}},
{$merge: { \"into\" : \"target\", \"whenMatched\" : \"replace\", \"whenNotMatched\" : \"discard\" }} // <---- does not throw
]));
assert.eq(error.code, ErrorCodes.StaleEpoch);
We don't get the expected exception with ErrorCodes.StaleEpoch:
[js_test:merge_stale_on_fields] sh2371| uncaught exception: Error: did not throw exception : [js_test:merge_stale_on_fields] sh2371| doassert@src/mongo/shell/assert.js:20:14 [js_test:merge_stale_on_fields] sh2371| assert.throws@src/mongo/shell/assert.js:577:13 [js_test:merge_stale_on_fields] sh2371| @(shell eval):57:31 [js_test:merge_stale_on_fields] sh2371| exiting with code -4