Last Updated: February 25, 2016
· carlosescri

Be careful dumping MongoDB's capped collections

A capped collection is a collection that should not grow more than a specified amount of bytes.

If you try to dump a BSON file with filtered results from a capped collection with mongodump and you import it into MongoDB in your dev laptop with mongorestore, MongoDB will reserve the amount of disk space specified in the companion metadata file.

Be careful because I recently imported a 30MB dump (filtered query) of a capped collection of 100G and MongoDB reserved space for those 100G in my laptop.

You have at least two solutions for this:

The first is to just edit the metadata file and edit the size of the capped collection to adapt to your development needs.

The metadata file looks like this:

    "options" : {
        "create" : "my_database.my_collection",
        "capped" : true,
        "size" : 107374182400
    "indexes" : [
            "v" : 1,
            "key" : { "_id" : 1 },
            "ns" : "my_database.my_collection",
            "name" : "_id_" 

The other solution is to use mongoexport instead and restore via mongoimport and then convert your collection to capped via the convertToCapped command with a proper size for the amount of data you exported.

Hope this helps someone :-)