Halo, kalau kamu merasa tulisan saya ngebantu kamu, kamu bisa ucapkan terima kasih lewat saweria .

Hello, if you find this article helpful, you can express your gratitude through saweria .



After Removing Collection & Database in MongoDB, Why Doesn’t It Free Up My Disk Space?

If you remove a collection or database in MongoDB, you don’t have to do anything; it will take time to free up disk space.

The time it takes depends on your server specifications. In my case, it takes 5-10 minutes to free up disk space after removing a collection or database.

However, it’s different if you remove some documents from a collection.


Remove Documents from Collection

In my experience, removing documents from a MongoDB collection will not free up your disk space immediately.

  1. In my case, it consumes my disk space. For example, if I remove documents with a size of 500MB, it will not free up my disk space; instead, it will use my existing disk space of 500MB.

  2. So, if you have little free space, it’s not safe to remove documents.

  3. To reclaim unused disk space, you should compact your collections :

    db.runCommand({ compact: 'your_collection' })
    # Again, it takes time to free up your disk space, so be patient.