summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/targetedTestsLastLtsFeatures/partial_indexes_downgrade.js
blob: 700354bdfb187ee55ea356b3788e04baacf9a9ed (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * Tests that we cannot downgrade FCV when we have partial indexes with $or/$in/$geoWithin.
 */

(function() {
'use strict';

const dbpath = MongoRunner.dataPath + 'partial_indexes_downgrade';
resetDbpath(dbpath);

// Start with 6.0, create a partial index with an $or, then make sure we fail to downgrade FCV
// to 5.0. Drop the index, then actually downgrade to 5.0.
{
    const conn =
        MongoRunner.runMongod({dbpath: dbpath, binVersion: 'latest', noCleanData: true});

    const db = conn.getDB('test');
    const coll = db['partial_indexes_downgrade'];
    assert.commandWorked(coll.createIndex(
        {a: 1, b: 1}, {partialFilterExpression: {$or: [{a: {$lt: 20}}, {b: {$lt: 10}}]}}));

    coll.insert({a: 1, b: 1});
    coll.insert({a: 30, b: 20});

    assert.commandFailedWithCode(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}),
                                    ErrorCodes.CannotDowngrade);
    coll.dropIndexes();
    assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}));

    MongoRunner.stopMongod(conn);
}

// Startup with 5.0 binary, with FCV set to 5.0.
{
    const conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: lastLTSFCV, noCleanData: true});

    const db = conn.getDB('test');
    const coll = db['partial_indexes_downgrade'];
    // Make sure we are on the same db path as before.
    assert.eq(coll.aggregate().toArray().length, 2);

    MongoRunner.stopMongod(conn);
}
})();