summaryrefslogtreecommitdiff
path: root/jstests/core/index_many.js
blob: 3fae520fe8119dee9df58e47d982c3b60cbb694f (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
45
46
47
48
49
50
51
// Cannot implicitly shard accessed collections because renameCollection command not supported
// on sharded collections.
// @tags: [assumes_unsharded_collection]

/* test using lots of indexes on one collection */

t = db.many;

function f() {
    t.drop();
    db.many2.drop();

    t.save({x: 9, y: 99});
    t.save({x: 19, y: 99});

    x = 2;
    var lastErr = null;
    while (x < 70) {
        patt = {};
        patt[x] = 1;
        if (x == 20)
            patt = {x: 1};
        if (x == 64)
            patt = {y: 1};
        lastErr = t.ensureIndex(patt);
        x++;
    }

    assert.commandFailed(lastErr, "should have got an error 'too many indexes'");

    // 40 is the limit currently
    lim = t.getIndexes().length;
    if (lim != 64) {
        print("# of indexes should be 64 but is : " + lim);
        return;
    }
    assert(lim == 64, "not 64 indexes");

    assert(t.find({x: 9}).length() == 1, "b");

    assert(t.find({y: 99}).length() == 2, "y idx");

    /* check that renamecollection remaps all the indexes right */
    assert(t.renameCollection("many2").ok, "rename failed");
    assert(t.find({x: 9}).length() == 0, "many2a");
    assert(db.many2.find({x: 9}).length() == 1, "many2b");
    assert(t.find({y: 99}).length() == 0, "many2c");
    assert(db.many2.find({y: 99}).length() == 2, "many2d");
}

f();