Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropping Mongo collection not clearing disk space

Tags:

mongodb

I have a collection with 750,000 documents, it's taking around 7Gb on the disk.

I've dropped the collection, but the files (test.0...test.11) are still on the disk.

  • If I delete them, then I loose all the collections, not just the one I dropped
  • Shouldn't Mongo be deleting them?

Just noticed that the database stats have an error.

{
    "ok" : 0,
    "errmsg" : "Collection [test.loadTest-2016-02-06 15:05:34Z] not found."
}
like image 250
BanksySan Avatar asked Sep 02 '25 17:09

BanksySan


1 Answers

You have dropped a collection, but not the database containing it. Dropping the collection does not compact the data files, nor does deleting a document. If you really want to compact the database, either drop it entirely and reimport it, or compact it using repairDatabase (see the docs). Beware though, you cannot compact the database online I think if you just have one node.

If you have a replica set, adding new nodes and removing the old ones is the safest way of compacting the database online. I do that from time to time and it's easy.

like image 179
Nicolas Avatar answered Sep 04 '25 10:09

Nicolas