Details

    • Type: Question
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      In docs:

      Unlike a standard collection, you must explicitly create a capped collection, specifying a collection size in bytes. The collection's data space is then preallocated. Note that the size specified includes database headers.

      But if we take a look at the following code, the insertion of document that larger 10 bytes is possible:

      Mongo m = new Mongo();
      DB db = m.getDB("test");
      db.createCollection("cn", BasicDBObjectBuilder.start()
              .add("size", 10)
              .add("capped", true)
              .get());
      DBCollection collection = db.getCollection("cn");
      collection.insert(BasicDBObjectBuilder.start()
              .add("field", "datadatadatadatadatadatadatadata")
              .add("maxLong", Long.MAX_VALUE)
              .add("minLong", Long.MIN_VALUE)
              .get()
      );
      System.out.println(collection.findOne());

        Activity

        Hide
        vitali_ausianik@epam.com Vitali Ausianik added a comment -

        Also we can see similar bug with Python

        import pymongo
         
        args = {"name": "tmpcoll", "options": { "capped": True, "size":5, "max":6} }
        db = pymongo.Connection().testdb
        db.create_collection(**args)
         
        to_ins = []
        to_ins.append({"field": "some string for add 1"})
        to_ins.append({"field": "some string for add 2"})
        to_ins.append({"field": "some string for add 3"})
         
        db.tmpcoll.insert(to_ins, safe=True)
         
        # Now we can find our three strings in collection "tmpcoll" as we inserted. The size of collection is 168b.
        # But we mustn't find them, because collection creates as capped with size 5b

        Show
        vitali_ausianik@epam.com Vitali Ausianik added a comment - Also we can see similar bug with Python import pymongo   args = {"name": "tmpcoll", "options": { "capped": True, "size":5, "max":6} } db = pymongo.Connection().testdb db.create_collection(**args)   to_ins = [] to_ins.append({"field": "some string for add 1"}) to_ins.append({"field": "some string for add 2"}) to_ins.append({"field": "some string for add 3"})   db.tmpcoll.insert(to_ins, safe=True)   # Now we can find our three strings in collection "tmpcoll" as we inserted. The size of collection is 168b. # But we mustn't find them, because collection creates as capped with size 5b
        Hide
        vitali_ausianik@epam.com Vitali Ausianik added a comment - - edited

        Should we create an additional issue?

        Python on Ubuntu 11.04 x64. We can create capped collection with negative size. And we can create such collection multiple times. After that we can't drop it.

        import pymongo
         
        args = {"name": "tmpcoll2", "options": { "capped": True, "size":-1, "max":6} }
        db = pymongo.Connection().testdb
         
        db.create_collection(**args)
        # Exception has been generated, but collection created successfully.

        Also we can reproduce this bug with shell

        MongoDB shell version: 2.0.2
        connecting to: test
        > use testdb
        switched to db testdb
        > db.dropDatabase()
        { "dropped" : "testdb", "ok" : 1 }
        > db.getCollectionNames()
        [ ]
        > db.createCollection("tmp1", {capped: true, size: -1})
        {
        	"errmsg" : "exception: create collection invalid size spec",
        	"code" : 10083,
        	"ok" : 0
        }
        > db.getCollectionNames()
        [ "tmp1" ]
        > db.createCollection("tmp1", {capped: true, size: -1})
        {
        	"errmsg" : "exception: create collection invalid size spec",
        	"code" : 10083,
        	"ok" : 0
        }
        > db.getCollectionNames()
        [ "tmp1", "tmp1" ]
        > db.createCollection("tmp1", {capped: true, size: -1})
        {
        	"errmsg" : "exception: create collection invalid size spec",
        	"code" : 10083,
        	"ok" : 0
        }
        > db.getCollectionNames()
        [ "tmp1", "tmp1", "tmp1" ]
        > db.tmp1.drop()
        false
        > db.getCollectionNames()
        [ "tmp1", "tmp1", "tmp1" ]

        Show
        vitali_ausianik@epam.com Vitali Ausianik added a comment - - edited Should we create an additional issue? Python on Ubuntu 11.04 x64. We can create capped collection with negative size. And we can create such collection multiple times. After that we can't drop it. import pymongo   args = {"name": "tmpcoll2", "options": { "capped": True, "size":-1, "max":6} } db = pymongo.Connection().testdb   db.create_collection(**args) # Exception has been generated, but collection created successfully. Also we can reproduce this bug with shell MongoDB shell version: 2.0.2 connecting to: test > use testdb switched to db testdb > db.dropDatabase() { "dropped" : "testdb", "ok" : 1 } > db.getCollectionNames() [ ] > db.createCollection("tmp1", {capped: true, size: -1}) { "errmsg" : "exception: create collection invalid size spec", "code" : 10083, "ok" : 0 } > db.getCollectionNames() [ "tmp1" ] > db.createCollection("tmp1", {capped: true, size: -1}) { "errmsg" : "exception: create collection invalid size spec", "code" : 10083, "ok" : 0 } > db.getCollectionNames() [ "tmp1", "tmp1" ] > db.createCollection("tmp1", {capped: true, size: -1}) { "errmsg" : "exception: create collection invalid size spec", "code" : 10083, "ok" : 0 } > db.getCollectionNames() [ "tmp1", "tmp1", "tmp1" ] > db.tmp1.drop() false > db.getCollectionNames() [ "tmp1", "tmp1", "tmp1" ]
        Hide
        eliot Eliot Horowitz added a comment -

        The minimum size for a capped collection is 4k.
        Anything smaller than that will get rounded up.

        For the -1 issue - please open a new ticket.

        Show
        eliot Eliot Horowitz added a comment - The minimum size for a capped collection is 4k. Anything smaller than that will get rounded up. For the -1 issue - please open a new ticket.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: