jstests/aggregation/extras/utils.js
/**
 * Assert that the given aggregation fails with a specific code. Error message is optional. Note
 * that 'code' can be an array of possible codes.
 */
Assert that the given aggregation fails with a specific code. Error message is optional. Note
that 'code' can be an array of possible codes.
Assert that the given aggregation fails with a specific code . Error message is optional . Note that ' code ' can be an array of possible codes .
function assertErrorCode(coll, pipe, code, errmsg, options = {}) {
    if (!Array.isArray(pipe)) {
        pipe = [pipe];
    }
    let cmd = {pipeline: pipe, cursor: {batchSize: 0}};
    for (let opt of Object.keys(options)) {
        cmd[opt] = options[opt];
    }
    let resultObj = coll.runCommand("aggregate", cmd);
    if (resultObj.ok) {
        let followupBatchSize = 0;  
        let cursor = new DBCommandCursor(coll.getDB(), resultObj, followupBatchSize);
        let assertThrowsMsg = "expected one of the following error codes: " + tojson(code);
        resultObj = assert.throws(() => cursor.itcount(), [], assertThrowsMsg);
    }
    assert.commandFailedWithCode(resultObj, code, errmsg);
}
function assertErrorCode ( coll , pipe , code , errmsg , options = { } ) { if ( ! Array . isArray ( pipe ) ) { pipe = [ pipe ] ; } let cmd = { pipeline : pipe , cursor : { batchSize : 0 } } ; for ( let opt of Object . keys ( options ) ) { cmd [ opt ] = options [ opt ] ; } let resultObj = coll . runCommand ( "aggregate" , cmd ) ; if ( resultObj . ok ) { let followupBatchSize = 0 ; let cursor = new DBCommandCursor ( coll . getDB ( ) , resultObj , followupBatchSize ) ; let assertThrowsMsg = "expected one of the following error codes: " + tojson ( code ) ; resultObj = assert . throws ( ( ) => cursor . itcount ( ) , [ ] , assertThrowsMsg ) ; } assert . commandFailedWithCode ( resultObj , code , errmsg ) ; }
Assert that the given aggregation fails with a specific code.
Assert that the given aggregation fails with a specific code .
// default