summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workload_modifiers/drop_all_indexes.js
blob: 9332ef4f7c683c4acf9e7b3dc19b92f3a552867e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';

/**
 * drop_all_indexes.js
 *
 * Defines a modifier for workloads that drops all indexes created by the
 * base workload's setup function. The implicit _id index and any indexes
 * that already existed at the start of setup are not dropped.
 */

function dropAllIndexes($config, $super) {
    $config.setup = function setup(db, collName, cluster) {
        var oldIndexes = db[collName].getIndexes().map(function(ixSpec) {
            return ixSpec.name;
        });

        $super.setup.apply(this, arguments);

        // drop each index that wasn't present before calling super
        db[collName].getIndexes().forEach(function(ixSpec) {
            var name = ixSpec.name;
            if (name !== '_id_' && !Array.contains(oldIndexes, name)) {
                var res = db[collName].dropIndex(name);
                assertAlways.commandWorked(res);
            }
        });
    };

    return $config;
}