jstests/noPassthrough/libs/index_build.js
/**
     * Runs listIndexes command on collection.
     * If 'options' is provided, these will be sent along with the command request.
     * Asserts that all the indexes on this collection fit within the first batch of results.
     * Returns a map of index specs keyed by name.
     */
Runs listIndexes command on collection.
If 'options' is provided, these will be sent along with the command request.
Asserts that all the indexes on this collection fit within the first batch of results.
Returns a map of index specs keyed by name.
Runs listIndexes command on collection . If ' options ' is provided these will be sent along with the command request . Asserts that all the indexes on this collection fit within the first batch of results . Returns a map of index specs keyed by name .
static assertIndexes(coll, numIndexes, readyIndexes, notReadyIndexes, options) {
        notReadyIndexes = notReadyIndexes || [];
        options = options || {};
        let res = assert.commandWorked(coll.runCommand("listIndexes", options));
        assert.eq(numIndexes,
                  res.cursor.firstBatch.length,
                  'unexpected number of indexes in collection: ' + tojson(res));
        assert.eq(0, res.cursor.id);
        const indexMap = res.cursor.firstBatch.reduce((m, spec) => {
            if (spec.hasOwnProperty('buildUUID')) {
                m[spec.spec.name] = spec;
            } else {
                m[spec.name] = spec;
            }
            return m;
        }, {});
        for (let name of readyIndexes) {
            assert(indexMap.hasOwnProperty(name),
                   'ready index ' + name + ' missing from listIndexes result: ' + tojson(res));
            const spec = indexMap[name];
            assert(!spec.hasOwnProperty('buildUUID'),
                   'unexpected buildUUID field in ' + name + ' index spec: ' + tojson(spec));
        }
        for (let name of notReadyIndexes) {
            assert(indexMap.hasOwnProperty(name),
                   'not-ready index ' + name + ' missing from listIndexes result: ' + tojson(res));
            const spec = indexMap[name];
            if (options.includeBuildUUIDs) {
                assert(spec.hasOwnProperty('spec'),
                       'expected spec field in ' + name + ': ' + tojson(spec));
                assert(spec.hasOwnProperty('buildUUID'),
                       'expected buildUUID field in ' + name + ': ' + tojson(spec));
            } else {
                assert(!spec.hasOwnProperty('buildUUID'),
                       'unexpected buildUUID field in ' + name + ' index spec: ' + tojson(spec));
            }
        }
        return indexMap;
    }
static assertIndexes ( coll , numIndexes , readyIndexes , notReadyIndexes , options ) { notReadyIndexes = notReadyIndexes || [ ] ; options = options || { } ; let res = assert . commandWorked ( coll . runCommand ( "listIndexes" , options ) ) ; assert . eq ( numIndexes , res . cursor . firstBatch . length , 'unexpected number of indexes in collection: ' + tojson ( res ) ) ; assert . eq ( 0 , res . cursor . id ) ; const indexMap = res . cursor . firstBatch . reduce ( ( m , spec ) => { if ( spec . hasOwnProperty ( 'buildUUID' ) ) { m [ spec . spec . name ] = spec ; } else { m [ spec . name ] = spec ; } return m ; } , { } ) ; for ( let name of readyIndexes ) { assert ( indexMap . hasOwnProperty ( name ) , 'ready index ' + name + ' missing from listIndexes result: ' + tojson ( res ) ) ; const spec = indexMap [ name ] ; assert ( ! spec . hasOwnProperty ( 'buildUUID' ) , 'unexpected buildUUID field in ' + name + ' index spec: ' + tojson ( spec ) ) ; } for ( let name of notReadyIndexes ) { assert ( indexMap . hasOwnProperty ( name ) , 'not-ready index ' + name + ' missing from listIndexes result: ' + tojson ( res ) ) ; const spec = indexMap [ name ] ; if ( options . includeBuildUUIDs ) { assert ( spec . hasOwnProperty ( 'spec' ) , 'expected spec field in ' + name + ': ' + tojson ( spec ) ) ; assert ( spec . hasOwnProperty ( 'buildUUID' ) , 'expected buildUUID field in ' + name + ': ' + tojson ( spec ) ) ; } else { assert ( ! spec . hasOwnProperty ( 'buildUUID' ) , 'unexpected buildUUID field in ' + name + ' index spec: ' + tojson ( spec ) ) ; } } return indexMap ; }
Runs listIndexes command on collection.
Runs listIndexes command on collection .
// First batch contains all the indexes in the collection. // A map of index specs keyed by index name. // Check ready indexes. // Check indexes that are not ready.