Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-12998

Can upsert document over 16MB

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Write Ops
    • ALL

      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
      

            Assignee:
            greg_10gen Greg Studer
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: