jstests/aggregation/extras/utils.js
/**
 * Compare two sets of documents (expressed as arrays) to see if they match. The two sets must have
 * the same documents, although the order need not match and values for fields defined in
 * "fieldsToSkip" need not match.
 *
 * Are non-scalar values references?
 */
Compare two sets of documents (expressed as arrays) to see if they match. The two sets must have
the same documents, although the order need not match and values for fields defined in
"fieldsToSkip" need not match.


Compare two sets of documents ( expressed as arrays ) to see if they match . The two sets must have the same documents although the order need not match and values for fields defined in " fieldsToSkip " need not match .
function resultsEq(rl, rr, verbose = false, fieldsToSkip = []) {
    const debug = msg => verbose ? print(msg) : null;  
    rl = arrayShallowCopy(rl);
    rr = arrayShallowCopy(rr);
    if (rl.length != rr.length) {
        debug(`resultsEq:  array lengths do not match ${tojson(rl)}, ${tojson(rr)}`);
        return false;
    }
    for (let i = 0; i < rl.length; ++i) {
        let foundIt = false;
        for (let j = 0; j < rr.length; ++j) {
            if (!anyEq(rl[i], rr[j], verbose, null, fieldsToSkip))
                continue;
            rr.splice(j, 1);
            foundIt = true;
            break;
        }
        if (!foundIt) {
            debug(`resultsEq: search target missing index ${i} (${tojson(rl[i])})`);
            return false;
        }
    }
    assert(!rr.length);
    return true;
}
function resultsEq ( rl , rr , verbose = false , fieldsToSkip = [ ] ) { const debug = msg => verbose ? print ( msg ) : null ; rl = arrayShallowCopy ( rl ) ; rr = arrayShallowCopy ( rr ) ; if ( rl . length != rr . length ) { debug ( ` ${ tojson ( rl ) } ${ tojson ( rr ) } ` ) ; return false ; } for ( let i = 0 ; i < rl . length ; ++ i ) { let foundIt = false ; for ( let j = 0 ; j < rr . length ; ++ j ) { if ( ! anyEq ( rl [ i ] , rr [ j ] , verbose , null , fieldsToSkip ) ) continue ; rr . splice ( j , 1 ) ; foundIt = true ; break ; } if ( ! foundIt ) { debug ( ` ${ i } ${ tojson ( rl [ i ] ) } ` ) ; return false ; } } assert ( ! rr . length ) ; return true ; }
Compare two sets of documents (expressed as arrays) to see if they match.
Compare two sets of documents ( expressed as arrays ) to see if they match .
// Helper to log 'msg' iff 'verbose' is true. // Make clones of the arguments so that we don't damage them. // Find a match in the other array. // Because we made the copies above, we can edit these out of the arrays so we don't // check on them anymore. // For the inner loop, we're going to be skipping out, so we don't need to be too // careful. // If we got here, we didn't find this item.