summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/insertMulti.js
blob: 4715199127d0d7c2c03203181cef673f780281a9 (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
52
53
// check the insertMulti path works, including the error handling

(function() {
"use strict";

function makeDocument(docSize) {
    var doc = {"fieldName": ""};
    var longString = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    while (Object.bsonsize(doc) < docSize) {
        if (Object.bsonsize(doc) < docSize - longString.length) {
            doc.fieldName += longString;
        } else {
            doc.fieldName += "x";
        }
    }
    return doc;
}

var t = db.foo;

t.drop();
assert.commandWorked(t.insert([{_id: 1}, {_id: 2}]));
assert.eq(t.count(), 2);
// no ContinueOnError
assert.commandFailedWithCode(t.insert([{_id: 3}, {_id: 2}, {_id: 4}], 0), ErrorCodes.DuplicateKey);
assert.eq(t.count(), 3);
assert.eq(t.count({"_id": 1}), 1);
assert.eq(t.count({"_id": 2}), 1);
assert.eq(t.count({"_id": 3}), 1);
assert.eq(t.count({"_id": 4}), 0);

assert(t.drop());
assert.commandWorked(t.insert([{_id: 1}, {_id: 2}]));
assert.eq(t.count(), 2);
// ContinueOnError
assert.commandFailedWithCode(t.insert([{_id: 3}, {_id: 2}, {_id: 4}], 1), ErrorCodes.DuplicateKey);
assert.eq(t.count(), 4);
assert.eq(t.count({"_id": 1}), 1);
assert.eq(t.count({"_id": 2}), 1);
assert.eq(t.count({"_id": 3}), 1);
assert.eq(t.count({"_id": 4}), 1);

// Push a large vector in bigger than the subset size we'll break it up into
assert(t.drop());
var doc = makeDocument(16 * 1024);
var docs = [];
for (var i = 0; i < 1000; i++)
    docs.push(Object.extend({}, doc));
assert.commandWorked(t.insert(docs));
assert.eq(t.count(), docs.length);

assert(t.drop());
})();