Search code examples
mongodbcapped-collections

Size of MongoDB capped collection is not right?


I have a capped collection. When I call stats() on it I get following output:

/* 0 */
{
    "ns" : "log_db.access_logs",
    "count" : 42088,
    "size" : 13602632,
    "avgObjSize" : 323,
    "storageSize" : 100003840,
    "numExtents" : 1,
    "nindexes" : 2,
    "lastExtentSize" : 100003840,
    "paddingFactor" : 1,
    "systemFlags" : 1,
    "userFlags" : 0,
    "totalIndexSize" : 3932656,
    "indexSizes" : {
        "_id_" : 1389920,
        "apikey_1_ts_1" : 2542736
    },
    "capped" : true,
    "max" : NumberLong(9223372036854775807),
    "ok" : 1
}

I don't know what 'max' parameter is showing. I created this collection using db.runCommand('convertToCapped' ... ) construct and I had put the 'size' parameter to be 100 million. But here there's no mention of it (size)

Can someone explain the meaning of 'max' field here and also how to find correct size of a capped collection.


Solution

  • I had this exact question once, since it was not in the documentation and this is the answer I got from a 10gen (MongoDB Inc) employee mongodb capped collection is not using all available space :

    The max property is an (optional) maximum number of documents to allow in the capped collection (see db.createCollection()). If you don't specify a max value, it will be set to MAXINT (in your example, the maximum positive value for a signed Int64). Since space for capped collections is always preallocated, the size limit takes precedence over the max number of documents.