Why does MongoDB takes up so much space? Why does MongoDB takes up so much space? mongodb mongodb

Why does MongoDB takes up so much space?


Basically, this is mongo preparing for the insertion of data. Mongo performs prealocation of storage for data to prevent (or minimize) fragmentation on the disk. This prealocation is observed in the form of a file that the mongod instance creates.

First it creates a 64MB file, next 128MB, next 512MB, and on and on until it reaches files of 2GB (the maximum size of prealocated data files).

There are some more things that mongo does that might be suspect to using more disk space, things like journaling...

For much, much more info on how mongoDB uses storage space, you can take a look at this page and in specific the section titled Why are the files in my data directory larger than the data in my database?

There are some things that you can do to minimize the space that is used, but these tequniques (such as using the --smallfiles option) are usually only recommended for development and testing use - never for production.


Question: Should you use SQL or MongoDB?

Answer: It depends.

Better way to ask the question: Should you use use a relational database or a document database?

Answer:

  • If your data is highly structured (every row has the same fields), or you rely heavily on foreign keys and you need strong transactional integrity on operations that use those related records... use a relational database.
  • If your records are heterogeneous (different fields per document) or have variable length fields (arrays) or have embedded documents (hierarchical)... use a document database.

My current software project uses both. Use the right tool for the job!