jstests/sharding/index_and_collection_option_propagation.js
// Helper function that runs listIndexes against shards to check for the existence of an index.
Helper function that runs listIndexes against shards to check for the existence of an index.
Helper function that runs listIndexes against shards to check for the existence of an index .
function checkShardIndexes(indexKey, shardsWithIndex, shardsWithoutIndex) {
    function shardHasIndex(indexKey, shard) {
        const res = shard.getDB(dbName).runCommand({listIndexes: collName});
        if (res.code === ErrorCodes.NamespaceNotFound) {
            return [res, false];
        }
        assert.commandWorked(res);
        for (index of res.cursor.firstBatch) {
            if (index.key.hasOwnProperty(indexKey)) {
                return [res, true];
            }
        }
        return [res, false];
    }
    for (shard of shardsWithIndex) {
        [listIndexesRes, foundIndex] = shardHasIndex(indexKey, shard);
        assert(foundIndex,
               "expected to see index with key " + indexKey + " in listIndexes response from " +
                   shard + ": " + tojson(listIndexesRes));
    }
    for (shard of shardsWithoutIndex) {
        [listIndexesRes, foundIndex] = shardHasIndex(indexKey, shard);
        assert(!foundIndex,
               "expected not to see index with key " + indexKey + " in listIndexes response from " +
                   shard + ": " + tojson(listIndexesRes));
    }
}
function checkShardIndexes ( indexKey , shardsWithIndex , shardsWithoutIndex ) { function shardHasIndex ( indexKey , shard ) { const res = shard . getDB ( dbName ) . runCommand ( { listIndexes : collName } ) ; if ( res . code === ErrorCodes . NamespaceNotFound ) { return [ res , false ] ; } assert . commandWorked ( res ) ; for ( index of res . cursor . firstBatch ) { if ( index . key . hasOwnProperty ( indexKey ) ) { return [ res , true ] ; } } return [ res , false ] ; } for ( shard of shardsWithIndex ) { [ listIndexesRes , foundIndex ] = shardHasIndex ( indexKey , shard ) ; assert ( foundIndex , "expected to see index with key " + indexKey + " in listIndexes response from " + shard + ": " + tojson ( listIndexesRes ) ) ; } for ( shard of shardsWithoutIndex ) { [ listIndexesRes , foundIndex ] = shardHasIndex ( indexKey , shard ) ; assert ( ! foundIndex , "expected not to see index with key " + indexKey + " in listIndexes response from " + shard + ": " + tojson ( listIndexesRes ) ) ; } }
Helper function that runs listIndexes against shards to check for the existence of an index.
Helper function that runs listIndexes against shards to check for the existence of an index .