[SERVER-12998] Can upsert document over 16MB Created: 03/Mar/14  Updated: 10/Dec/14  Resolved: 03/Mar/14

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

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Greg Studer
Resolution: Duplicate Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-12973 update command can make document larg... Closed
Related
Operating System: ALL
Participants:

 Description   

This requires a shell patched to remove 16MB limits so it can send oversized docs to the server. The server was not patched so limits should be enforced. They are correctly enforced for inserts.

> var maxSize = 16*1024*1024;
> var overheadWithId = Object.bsonsize({_id: ObjectId(), str:''});
> var id = ObjectId();
> var str = new Array(maxSize - overheadWithId + 1/*one byte over*/ + 1/*commas are separators*/).toString();
> var obj = {_id: id, str: str};
> assert.eq(Object.bsonsize(obj), maxSize+1);
> db.tooBig.drop();
false
> db.tooBig.runCommand('insert', {documents: [obj]});
{
        "ok" : 1,
        "n" : 0,
        "writeErrors" : [
                {
                        "index" : 0,
                        "code" : 2,
                        "errmsg" : "object to insert too large16777217"
                }
        ]
}
> db.tooBig.runCommand('update', {updates: [{q:obj, u:{$set:{a:1}}, upsert:true}]});
{
        "ok" : 1,
        "nModified" : 0,
        "n" : 1,
        "upserted" : [
                {
                        "index" : 0,
                        "_id" : ObjectId("5314d1f6f0a5a83253a57d04")
                }
        ]
}
> assert.lte(Object.bsonsize(db.tooBig.findOne()), maxSize);
assert: 16777228 is not less than or eq 16777216 : undefined
Error: 16777228 is not less than or eq 16777216 : undefined
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at Function.assert.lte (src/mongo/shell/assert.js:293:5)
    at (shell):1:8
2014-03-03T14:03:18.778-0500 Error: 16777228 is not less than or eq 16777216 : undefined at src/mongo/shell/assert.js:13
> db.tooBig.drop();
true
> db.tooBig.runCommand('update', {updates: [{q:{}, u:obj, upsert:true}]});
{
        "ok" : 1,
        "nModified" : 0,
        "n" : 1,
        "upserted" : [
                {
                        "index" : 0,
                        "_id" : ObjectId("5314d1f6f0a5a83253a57d04")
                }
        ]
}
> assert.lte(Object.bsonsize(db.tooBig.findOne()), maxSize);
assert: 16777217 is not less than or eq 16777216 : undefined
Error: 16777217 is not less than or eq 16777216 : undefined
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at Function.assert.lte (src/mongo/shell/assert.js:293:5)
    at (shell):1:8
2014-03-03T14:03:18.882-0500 Error: 16777217 is not less than or eq 16777216 : undefined at src/mongo/shell/assert.js:13
> db.tooBig.drop();
true
> db.tooBig.runCommand('update', {updates: [{q:{}, u:{$set:obj}, upsert:true}]});
{
        "ok" : 1,
        "nModified" : 0,
        "n" : 1,
        "upserted" : [
                {
                        "index" : 0,
                        "_id" : ObjectId("5314d1f6f0a5a83253a57d04")
                }
        ]
}
> assert.lte(Object.bsonsize(db.tooBig.findOne()), maxSize);
assert: 16777217 is not less than or eq 16777216 : undefined
Error: 16777217 is not less than or eq 16777216 : undefined
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at Function.assert.lte (src/mongo/shell/assert.js:293:5)
    at (shell):1:8
2014-03-03T14:03:18.980-0500 Error: 16777217 is not less than or eq 16777216 : undefined at src/mongo/shell/assert.js:13


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