Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have read a post from Parse [1] that you can run compact in order to save the index size on the MongoDB.

Our total index size is 10GB, and our total memory memory is 12GB, as you might know the MongoDB perform badly when index size is near the size of memory, so we tried to run compact and reduced the size to become to 7GB.

However, after 1 week, the size grown back to 10GB, so currently we have a schedule job to run the compact commands.

I am thinking if this really help, and why the index grow so quickly and stabilized when it reach the 10GB?


share|improve this question

Parse has a unique issue -- they don't know how people are using the MongoDBs they provide. Most people relying on a Parse as a use case for managing their MongoDB will mostly read about how Parse tries to fix poor usage by their customers.

That being said, you shouldn't always be compacting. In fact, if you are having to compact regularly, it means you are using MongoDB inefficiently. The reasons your MongoDB may become "defragmented" are:

  • Regularly deleting documents
  • Updating documents and making the document larger continually (does not include atomic updates)

If you are regularly deleting documents, then you should consider using TTL or capped collections.

If you are updating documents and making the document larger (i.e. continuously extending an array), then you should consider redesigning schema to limit the unlimited document growth. Or, you can consider adding padding as placeholders for the future updates.

Either way, if you are having to compact regularly and often, it is a symptom of not using MongoDB correctly, and you should consider redesigning your schema. Compactions are blocking commands and on datasizes larger than a few gigs can take a while to complete.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.