[SERVER-12973] update command can make document larger than 16MB Created: 28/Feb/14  Updated: 11/Jul/16  Resolved: 13/Mar/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.6.0-rc0
Fix Version/s: 2.6.0-rc2

Type: Bug Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-12998 Can upsert document over 16MB Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

var maxBsonObjectSize = db.isMaster().maxBsonObjectSize;
var bigness = maxBsonObjectSize + 16261;
var big_string = '';
 
while (big_string.length < bigness) big_string += 'a';
 
db.collection.drop();
var result = db.runCommand({
    update: 'collection',
    ordered: true,
    updates: [
        {
            q: {x: 1},
            u: {$set: {s: big_string}},
            multi: false,
            upsert: true
        }
    ]
});
 
printjson(result);
var overbigness = Object.bsonsize(db.collection.findOne()) - maxBsonObjectSize;
print('made document ' + overbigness + ' bytes too big.')

Participants:

 Description   

The "update" command with "upsert: true" can make documents up to 16302 bytes larger than maxBsonObjectSize.



 Comments   
Comment by Githook User [ 13/Mar/14 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-12973 update command can make document larger than 16MB
Branch: v2.6
https://github.com/mongodb/mongo/commit/f4d08212ef92ed07f1a72b59f0b3b781db55810a

Comment by Githook User [ 13/Mar/14 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-12973 update command can make document larger than 16MB
Branch: master
https://github.com/mongodb/mongo/commit/e2c1d460b874e4deffcd7f18e32a45284d84d0d5

Comment by A. Jesse Jiryu Davis [ 05/Mar/14 ]

With 2.4.9's mongod and shell, it looks like I can make a document at most 17 bytes too big:

var maxBsonObjectSize = db.isMaster().maxBsonObjectSize;
var bigness = maxBsonObjectSize - 24;
var big_string = '';
 
while (big_string.length < bigness) big_string += 'a';
 
db.collection.drop();
var result = db.collection.update(
    {x: 1},
    {$set: {s: big_string}},
    true);
 
printjson(db.getLastErrorObj());
var overbigness = Object.bsonsize(db.collection.findOne()) - maxBsonObjectSize;
print('made document ' + overbigness + ' bytes too big.');

Result:

{
	"updatedExisting" : false,
	"upserted" : ObjectId("53177d64758be60887fe822c"),
	"n" : 1,
	"connectionId" : 23,
	"err" : null,
	"ok" : 1
}
made document 17 bytes too big.

If I try to make a document 18 bytes too big, I get:

{
	"err" : "update object too large",
	"code" : 10055,
	"n" : 0,
	"connectionId" : 22,
	"ok" : 1
}

This behavior in 2.4 perhaps merits its own ticket.

Comment by Greg Studer [ 05/Mar/14 ]

Can we check if this is a regression?

Generated at Thu Feb 08 03:30:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.