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

Incompatible to update capped collection after upgrade to MongoDB-3.2

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 3.2.6
    • Fix Version/s: None
    • Component/s: Storage
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      use mongo shell to create a capped collection

      db.createCollection("capped", {capped: 1, max: 5000, size: 1000000})
      db.capped.insert({id: "test", x: 0})
      

      when use nodejs client to update this document, db.capped.update(

      {id: "test}

      , {$set: {x: 1}}), it will receive an error.

      Cannot change the size of a document in a capped collection: 33 != 29
      

      Show
      use mongo shell to create a capped collection db.createCollection("capped", {capped: 1, max: 5000, size: 1000000}) db.capped.insert({id: "test", x: 0}) when use nodejs client to update this document, db.capped.update( {id: "test} , {$set: {x: 1}}), it will receive an error. Cannot change the size of a document in a capped collection: 33 != 29

      Description

      Background

      Different drivers may have different way to encode a integer to BSON´╝î eg: when insert a document

      {status: 1}

      * mongoshell encode 1 to a 8bytes data,  server received a request {status: 1.0}.
      * nodejs driver encode 1 to 4bytes data, server received a request {status: 1}
      
      

      MongoDB 3.2 behaivor

      MongoDB-3.2 added on a new condition check when update a capped collection, this is suitable for all storage engines. Which means user "Cannot change the size of a document in a capped collection".

      db/catalog/collection.cpp:556
          const auto oldSize = oldDoc.value().objsize();
          if (_recordStore->isCapped() && oldSize != newDoc.objsize())
              return {ErrorCodes::CannotGrowDocumentInCappedNamespace,
                      str::stream() << "Cannot change the size of a document in a capped collection: "
                                    << oldSize << " != " << newDoc.objsize()};
      

      MongoDB 3.0 behaivor

      In mongodb 3.0, only mmapv1 have limitation to update a capped collection, that is "objects in a capped ns cannot grow(no need have the same size with old document".

       
      if (isCapped())
              return StatusWith<RecordId>(
                  ErrorCodes::InternalError, "failing update: objects in a capped ns cannot grow", 10003);
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: