jstests/multiVersion/genericBinVersion/keystring_index.js
// Populate the database using the config specified by the indexTypes array.
Populate the database using the config specified by the indexTypes array.
Populate the database using the config specified by the indexTypes array .
function populateDb(testDb) {
    indexTypes.forEach(indexOptions => {
        [true, false].forEach(unique => {
            [1, 2].forEach(indexVersion => {
                let indexName = indexOptions.indexName;
                if ((indexName == "hashed" || indexName == "wildCard") &&
                    (unique === true || indexVersion === 1))
                    return;
                indexName += unique === true ? "Unique" : "NotUnique";
                indexName += `Version${indexVersion}`;
                let collectionName = kCollectionPrefix + '_' + indexName;
                print(`${indexName}: Creating Collection`);
                assert.commandWorked(testDb.createCollection(collectionName));
                print(`${indexName}: Inserting Documents`);
                if (unique)
                    insertDocumentsUnique(testDb[collectionName], kNumDocs, indexOptions.createDoc);
                else
                    insertDocumentsNotUnique(
                        testDb[collectionName], kNumDocs, indexOptions.createDoc);
                let extraCreateIndexOptions = {
                    name: indexName,
                    v: NumberLong(indexVersion),
                    unique: unique === true
                };
                if ("createIndexOptions" in indexOptions)
                    extraCreateIndexOptions =
                        Object.extend(extraCreateIndexOptions, indexOptions.createIndexOptions);
                print(JSON.stringify(extraCreateIndexOptions));
                print(`${indexName}: Creating Index`);
                assert.commandWorked(
                    testDb[collectionName].createIndex(indexOptions.spec, extraCreateIndexOptions));
                let indexSpec = getIndexSpecByName(testDb[collectionName], indexName);
                assert.eq(indexVersion, indexSpec.v, tojson(indexSpec));
            });
        });
    });
}
function populateDb ( testDb ) { indexTypes . forEach ( indexOptions => { [ true , false ] . forEach ( unique => { [ 1 , 2 ] . forEach ( indexVersion => { let indexName = indexOptions . indexName ; if ( ( indexName == "hashed" || indexName == "wildCard" ) && ( unique === true || indexVersion === 1 ) ) return ; indexName += unique === true ? "Unique" : "NotUnique" ; indexName += ` ${ indexVersion } ` ; let collectionName = kCollectionPrefix + '_' + indexName ; print ( ` ${ indexName } ` ) ; assert . commandWorked ( testDb . createCollection ( collectionName ) ) ; print ( ` ${ indexName } ` ) ; if ( unique ) insertDocumentsUnique ( testDb [ collectionName ] , kNumDocs , indexOptions . createDoc ) ; else insertDocumentsNotUnique ( testDb [ collectionName ] , kNumDocs , indexOptions . createDoc ) ; let extraCreateIndexOptions = { name : indexName , v : NumberLong ( indexVersion ) , unique : unique === true } ; if ( "createIndexOptions" in indexOptions ) extraCreateIndexOptions = Object . extend ( extraCreateIndexOptions , indexOptions . createIndexOptions ) ; print ( JSON . stringify ( extraCreateIndexOptions ) ) ; print ( ` ${ indexName } ` ) ; assert . commandWorked ( testDb [ collectionName ] . createIndex ( indexOptions . spec , extraCreateIndexOptions ) ) ; let indexSpec = getIndexSpecByName ( testDb [ collectionName ] , indexName ) ; assert . eq ( indexVersion , indexSpec . v , tojson ( indexSpec ) ) ; } ) ; } ) ; } ) ; }
Populate the database using the config specified by the indexTypes array.
Populate the database using the config specified by the indexTypes array .
// Create a new collection and index for each indexType in the array. // Try unique and non-unique. // Try index-version 1 and 2. // We only run V2 non-unique for hashed and wildCard because they don't exist in // v1. // Assert that the correct index type was created.