12

I have a database in MongoDB, called dump. Currently, it reached 6GB in my server. I decided to delete 90% of data in this database to reduce the disk space it occupied. But after doing that its size is still 6GB, while the true storage size is only 250MB.

I guess this is the design of MongoDB? Is there any convinient way to reduce its size? Thank in advance.

Community
  • 1
  • 1
user342960
  • 317
  • 2
  • 4
  • 11

2 Answers2

18

Try (source):

$ mongo mydb
> db.repairDatabase()
Himavanth
  • 400
  • 5
  • 15
Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
5

To compress the data files, you can run either start up MongoDB with mongod --repair, or connect to the database through the shell and run db.repairDatabase().

There's also a new compact command scheduled for v1.9 that will do in-place compaction.

Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
  • 5
    fyi for 'compact' the docs say: "This operation will not reduce the amount of disk space used on the filesystem. Storage size is the amount of data allocated within the database files, not the size/number of the files on file system." Repair is still the only option to recover disk space. – Darryl E. Clarke Feb 01 '12 at 18:52