jstests/libs/check_unique_indexes.js
/**
 * Verifies that all unique indexes belonging to all collections on all databases on the server
 * are in correct data format version.
 */
Verifies that all unique indexes belonging to all collections on all databases on the server
are in correct data format version.
Verifies that all unique indexes belonging to all collections on all databases on the server are in correct data format version .
function checkUniqueIndexFormatVersion(adminDB) {
    const isWiredTiger =
        assert.commandWorked(adminDB.serverStatus()).storageEngine.name === "wiredTiger";
    if (!isWiredTiger)
        return;
    res = assert.commandWorked(adminDB.runCommand({"listDatabases": 1}));
    let databaseList = res.databases;
    databaseList.forEach(function(database) {
        let currentDatabase = adminDB.getSiblingDB(database.name);
        let collectionsWithPending =
            currentDatabase.runCommand("listCollections", {includePendingDrops: true})
                .cursor.firstBatch;
        collectionsWithPending.forEach(function(c) {
            if (c.type == "view") {
                return;
            }
            let currentCollection = currentDatabase.getCollection(c.name);
            currentCollection.getIndexes().forEach(function(index) {
                if (index.unique && !index.clustered) {
                    let ifv = currentCollection.aggregate({$collStats: {storageStats: {}}})
                                  .next()
                                  .storageStats.indexDetails[index.name]
                                  .metadata.formatVersion;
                    if (index.v === 2) {
                        assert(ifv == 12 || ifv == 14,
                               "Expected index format version 12 or 14 for unique index: " +
                                   tojson(index));
                    } else {
                        assert(ifv == 11 || ifv == 13,
                               "Expected index format version 11 or 13 for unique index: " +
                                   tojson(index));
                    }
                }
            });
        });
    });
}
function checkUniqueIndexFormatVersion ( adminDB ) { const isWiredTiger = assert . commandWorked ( adminDB . serverStatus ( ) ) . storageEngine . name === "wiredTiger" ; if ( ! isWiredTiger ) return ; res = assert . commandWorked ( adminDB . runCommand ( { "listDatabases" : 1 } ) ) ; let databaseList = res . databases ; databaseList . forEach ( function ( database ) { let currentDatabase = adminDB . getSiblingDB ( database . name ) ; let collectionsWithPending = currentDatabase . runCommand ( "listCollections" , { includePendingDrops : true } ) . cursor . firstBatch ; collectionsWithPending . forEach ( function ( c ) { if ( c . type == "view" ) { return ; } let currentCollection = currentDatabase . getCollection ( c . name ) ; currentCollection . getIndexes ( ) . forEach ( function ( index ) { if ( index . unique && ! index . clustered ) { let ifv = currentCollection . aggregate ( { $collStats : { storageStats : { } } } ) . next ( ) . storageStats . indexDetails [ index . name ] . metadata . formatVersion ; if ( index . v === 2 ) { assert ( ifv == 12 || ifv == 14 , "Expected index format version 12 or 14 for unique index: " + tojson ( index ) ) ; } else { assert ( ifv == 11 || ifv == 13 , "Expected index format version 11 or 13 for unique index: " + tojson ( index ) ) ; } } } ) ; } ) ; } ) ; }
Verifies that all unique indexes belonging to all collections on all databases on the server
 are in correct data format version.
Verifies that all unique indexes belonging to all collections on all databases on the server are in correct data format version .
// Data format version is WiredTiger specific and not required to be tested for other // storage engines. // Get the list of collections including collections that are pending drop. This is to // ensure that every unique index has the correct format version.