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
- duplicates
-
SERVER-12973 update command can make document larger than 16MB
- Closed