1

I have a database (the name is HCM) which has 2 collections (coll A and coll B). This database occupies 17.9453125 GB (coll A: 13 Gb, coll B: 4.94.. GB - > I guess). Now I drop coll A by commands:

use HCM
db.A.drop()

after that I check database again and It still remains 17.94... GB. I think the size of database has to be reduced after dropping, but it's not !

Dennis Do
  • 480
  • 7
  • 24
  • 1
    This is a commonly asked question. See: [Reducing MongoDB database file size](http://stackoverflow.com/questions/2966687) for one example, or the [MongoDB storage FAQ](http://docs.mongodb.org/manual/faq/storage/#why-are-the-files-in-my-data-directory-larger-than-the-data-in-my-database). TL;DR: database storage is preallocated, so storage freed up by a dropped collection is available for reuse by other collections in that database. To rebuild the database and reclaim the space you need to use [`repair`](http://docs.mongodb.org/manual/reference/command/repairDatabase/#dbcmd.repairDatabase). – Stennie Jan 05 '14 at 05:22

1 Answers1

3

You need repairDatabase the db. You might have dropped your table, but the space originally used by that table within mongo's data files will NOT be freed up automatically. The repair operation will reduce the size of the data files.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • I think it will work, but unfortunately I meet an error "Cannot repair database ... having size: 19268632576 (bytes) because free disk space is : 2341548032 (bytes)". It hard for me to remove some important data to have enough space for repairing :(. Anyway, thanks for your help. – Dennis Do Jan 05 '14 at 05:36
  • 1
    a 19gig database on a system with only 2gig free space? You need to upgrade your drives... – Marc B Jan 05 '14 at 05:39