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

Incompatible to update capped collection after upgrade to MongoDB-3.2

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.6
    • Component/s: Storage
    • None
    • ALL
    • 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

      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);
      

            Assignee:
            stephen.steneker@mongodb.com Stennie Steneker (Inactive)
            Reporter:
            zyd_com@126.com Zhang Youdong
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: