Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB data remove - reclaim diskspace [duplicate]

Tags:

Possible Duplicate:
Auto compact the deleted space in mongodb?

My understanding is that on delete operations MongoDB won't free up the disk space but would reuse it as needed.

  1. Is that correct?
  2. If not, would I have run a repair command?
  3. Could the repair be run on a live mongo instance?
like image 960
griffin Avatar asked Apr 01 '11 20:04

griffin


People also ask

How do I free up disk space in MongoDB?

However, if you delete a lot of documents and want the WiredTiger storage engine to release this empty space to the operating system, you can defragment your data file. This is possible using the compact command. Let's see how data is stored and what happens when we delete the data and follow that run the compact.

What is the fastest operation to clear an entire collection in MongoDB?

To remove all documents from a collection, it may be more efficient to use the drop() method to drop the entire collection, including the indexes, and then recreate the collection and rebuild the indexes.

Which command is used to delete the data from MongoDB?

deleteMany() To delete a single document, use db. collection. deleteOne()

How much disk space does MongoDB use?

Starting in MongoDB 3.4, the default WiredTiger internal cache size is the larger of either: 50% of (RAM - 1 GB), or. 256 MB.


2 Answers

  1. Yes it is correct.
  2. No, better to give mongodb as much disk space as possible( if mongodb can allocate more space than less disk fragmentation you will have, in additional allocating space is expensive operation). But if you wish you can run db.repairDatabase() from mongodb shell to shrink database size.
  3. Yes you can run repairDatabase on live mongodb instance ( better to run it in none peak hours)
like image 198
Andrew Orsich Avatar answered Oct 02 '22 22:10

Andrew Orsich


This is somewhat of a duplicate of this MongoDB question ...

Auto compact the deleted space in mongodb?

See that answer for details on how to ...

  • Reclame some space
  • Use serverside JS to run a recurring job to get back space (including a script you can run ...)
  • How you might want to look into Capped Collections for some use cases!

Also you can see this related blog posting: http://learnmongo.com/posts/compacting-mongodb-data-files/

like image 28
Justin Jenkins Avatar answered Oct 02 '22 23:10

Justin Jenkins