jstests/core/apply_ops1.js
/**
 * Test function for running CRUD operations on non-existent namespaces using various
 * combinations of invalid namespaces (collection/database), allowAtomic and alwaysUpsert,
 * and nesting.
 *
 * Leave 'expectedErrorCode' undefined if this command is expected to run successfully.
 */
Test function for running CRUD operations on non-existent namespaces using various
combinations of invalid namespaces (collection/database), allowAtomic and alwaysUpsert,
and nesting.

Leave 'expectedErrorCode' undefined if this command is expected to run successfully.
Test function for running CRUD operations on non - existent namespaces using various combinations of invalid namespaces ( collection / database ) allowAtomic and alwaysUpsert and nesting . Leave ' expectedErrorCode ' undefined if this command is expected to run successfully .
function testCrudOperationOnNonExistentNamespace(optype, o, o2, expectedErrorCode) {
    expectedErrorCode = expectedErrorCode || ErrorCodes.OK;
    const t2 = db.getSiblingDB('apply_ops1_no_such_db').getCollection('t');
    [t, t2].forEach(coll => {
        const op = {op: optype, ns: coll.getFullName(), o: o, o2: o2};
        [false, true].forEach(nested => {
            const opToRun = nested ? {op: 'c', ns: 'test.$cmd', o: {applyOps: [op]}, o2: {}} : op;
            [false, true].forEach(allowAtomic => {
                [false, true].forEach(alwaysUpsert => {
                    const cmd = {
                        applyOps: [opToRun],
                        allowAtomic: allowAtomic,
                        alwaysUpsert: alwaysUpsert
                    };
                    jsTestLog('Testing applyOps on non-existent namespace: ' + tojson(cmd));
                    if (expectedErrorCode === ErrorCodes.OK) {
                        assert.commandWorked(db.adminCommand(cmd));
                    } else {
                        assert.commandFailedWithCode(db.adminCommand(cmd), expectedErrorCode);
                    }
                });
            });
        });
    });
}
function testCrudOperationOnNonExistentNamespace ( optype , o , o2 , expectedErrorCode ) { expectedErrorCode = expectedErrorCode || ErrorCodes . OK ; const t2 = db . getSiblingDB ( 'apply_ops1_no_such_db' ) . getCollection ( 't' ) ; [ t , t2 ] . forEach ( coll => { const op = { op : optype , ns : coll . getFullName ( ) , o : o , o2 : o2 } ; [ false , true ] . forEach ( nested => { const opToRun = nested ? { op : 'c' , ns : 'test.$cmd' , o : { applyOps : [ op ] } , o2 : { } } : op ; [ false , true ] . forEach ( allowAtomic => { [ false , true ] . forEach ( alwaysUpsert => { const cmd = { applyOps : [ opToRun ] , allowAtomic : allowAtomic , alwaysUpsert : alwaysUpsert } ; jsTestLog ( 'Testing applyOps on non-existent namespace: ' + tojson ( cmd ) ) ; if ( expectedErrorCode === ErrorCodes . OK ) { assert . commandWorked ( db . adminCommand ( cmd ) ) ; } else { assert . commandFailedWithCode ( db . adminCommand ( cmd ) , expectedErrorCode ) ; } } ) ; } ) ; } ) ; } ) ; }
Test function for running CRUD operations on non-existent namespaces using various
 combinations of invalid namespaces (collection/database), allowAtomic and alwaysUpsert,
 and nesting.
Test function for running CRUD operations on non - existent namespaces using various combinations of invalid namespaces ( collection / database ) allowAtomic and alwaysUpsert and nesting .