summaryrefslogtreecommitdiff
path: root/jstests/core/insert_illegal_doc.js
blob: d91866e87660b002f004a1f7b2e0f9e76a616a67 (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
// SERVER-12185: Do not allow insertion or update of docs which will fail the
// "parallel indexing of arrays" test
var coll = db.insert_illegal_doc;
coll.drop();
coll.ensureIndex({a: 1, b: 1});

var res;
// test upsert
res = coll.update({_id: 1}, {_id: 1, a: [1, 2, 3], b: [4, 5, 6]}, true);
assert.writeError(res);
assert.eq(res.getWriteError().code, ErrorCodes.CannotIndexParallelArrays);
assert.eq(0, coll.find().itcount(), "should not be a doc");

// test insert
res = coll.insert({_id: 1, a: [1, 2, 3], b: [4, 5, 6]});
assert.writeError(res);
assert.eq(res.getWriteError().code, ErrorCodes.CannotIndexParallelArrays);
assert.eq(0, coll.find().itcount(), "should not be a doc");

// test update
res = coll.insert({_id: 1});
assert.writeOK(res, "insert failed");
res = coll.update({_id: 1}, {$set: {a: [1, 2, 3], b: [4, 5, 6]}});
assert.writeError(res);
assert.eq(res.getWriteError().code, ErrorCodes.CannotIndexParallelArrays);
assert.eq(undefined, coll.findOne().a, "update should have failed");