summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/stress_test_unique_index_unique.js
blob: 85e66feafca4d850271f031c88939f50ecd530fc (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
/**
 * Tests that unique indexes can be built with a large number of unique values.
 */

(function() {
"use strict";

let coll = db.stress_test_unique_index_unique;
coll.drop();

const kNumDocs = 500000;  // ~15 MB

function loadCollectionWithDocs(collection, numDocs) {
    const kMaxChunkSize = 100000;

    let inserted = 0;
    while (inserted < numDocs) {
        let docs = [];
        for (let i = 0; i < kMaxChunkSize && inserted + docs.length < numDocs; i++) {
            docs.push({"a": inserted + i});
        }
        assert.commandWorked(collection.insertMany(docs, {ordered: false}));
        inserted += docs.length;
    }
}

loadCollectionWithDocs(coll, kNumDocs);

assert.commandWorked(coll.createIndex({a: 1}, {unique: true}));
})();