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
54
55
56
57
58
59
60
61
62
|
var maxBsonObjectSize = db.isMaster().maxBsonObjectSize;
var docOverhead = Object.bsonsize({_id: new ObjectId(), x: ''});
var maxStrSize = maxBsonObjectSize - docOverhead;
var maxStr = 'a';
while (maxStr.length < maxStrSize)
maxStr += 'a';
var coll = db.max_doc_size;
coll.drop();
var res = db.runCommand({insert: coll.getName(), documents: [{_id: new ObjectId(), x: maxStr}]});
assert(res.ok);
assert.eq(null, res.writeErrors);
coll.drop();
res = db.runCommand({
update: coll.getName(),
ordered: true,
updates: [{q: {a: 1}, u: {_id: new ObjectId(), x: maxStr}, upsert: true}]
});
assert(res.ok);
assert.eq(null, res.writeErrors);
coll.drop();
var id = new ObjectId();
coll.insert({_id: id});
res = db.runCommand(
{update: coll.getName(), ordered: true, updates: [{q: {_id: id}, u: {$set: {x: maxStr}}}]});
assert(res.ok);
assert.eq(null, res.writeErrors);
//
// Test documents over the size limit.
//
var overBigStr = maxStr + 'a';
coll.drop();
res = db.runCommand({insert: coll.getName(), documents: [{_id: new ObjectId(), x: overBigStr}]});
assert(res.ok);
assert.neq(null, res.writeErrors);
coll.drop();
res = db.runCommand({
update: coll.getName(),
ordered: true,
updates: [{q: {a: 1}, u: {_id: new ObjectId(), x: overBigStr}, upsert: true}]
});
assert(res.ok);
assert.neq(null, res.writeErrors);
coll.drop();
id = new ObjectId();
coll.insert({_id: id});
res = db.runCommand({
update: coll.getName(),
ordered: true,
updates: [{q: {_id: id}, u: {$set: {x: overBigStr}}}]
});
assert(res.ok);
assert.neq(null, res.writeErrors);
|