jstests/replsets/txn_override_unittests.js
/**
 * Runs a test where a transaction attempts to use a forbidden database name. When running a
 * CRUD operation on one of these databases, network_error_and_txn_override.js is expected to
 * commit the current transaction and run the CRUD operation outside of a transaction.
 */
Runs a test where a transaction attempts to use a forbidden database name. When running a
CRUD operation on one of these databases, network_error_and_txn_override.js is expected to
commit the current transaction and run the CRUD operation outside of a transaction.
Runs a test where a transaction attempts to use a forbidden database name . When running a CRUD operation on one of these databases network_error_and_txn_override . js is expected to commit the current transaction and run the CRUD operation outside of a transaction .
function testBadDBName(session, badDBName) {
    const badDB = session.getDatabase(badDBName);
    const badColl = badDB['foo'];
    assert.commandWorked(badDB.createCollection(collName1));
    assert.commandWorked(coll1.insert({_id: 1}));
    assert.eq(coll1.find().itcount(), 1);
    assert.commandWorked(badColl.insert({_id: 1}));
    assert.eq(coll1.find().itcount(), 1);
    assert.eq(badColl.find().itcount(), 1);
    assert.commandFailedWithCode(badColl.insert({_id: 1}), ErrorCodes.DuplicateKey);
    assert.eq(coll1.find().itcount(), 1);
    assert.eq(badColl.find().itcount(), 1);
}
function testBadDBName ( session , badDBName ) { const badDB = session . getDatabase ( badDBName ) ; const badColl = badDB [ 'foo' ] ; assert . commandWorked ( badDB . createCollection ( collName1 ) ) ; assert . commandWorked ( coll1 . insert ( { _id : 1 } ) ) ; assert . eq ( coll1 . find ( ) . itcount ( ) , 1 ) ; assert . commandWorked ( badColl . insert ( { _id : 1 } ) ) ; assert . eq ( coll1 . find ( ) . itcount ( ) , 1 ) ; assert . eq ( badColl . find ( ) . itcount ( ) , 1 ) ; assert . commandFailedWithCode ( badColl . insert ( { _id : 1 } ) , ErrorCodes . DuplicateKey ) ; assert . eq ( coll1 . find ( ) . itcount ( ) , 1 ) ; assert . eq ( badColl . find ( ) . itcount ( ) , 1 ) ; }
Runs a test where a transaction attempts to use a forbidden database name.
Runs a test where a transaction attempts to use a forbidden database name .
// We attempt another insert in the 'bad collection' that gets a 'DuplicateKey' error. // 'DuplicateKey' errors cause transactions to abort, so if this error were received in a // transaction, we would expect the transaction to get aborted and the collections to be // empty. Since this is not running in a transaction, even though the statement fails, the // previous inserts do not storage-rollback.