title: How to "defragment" MongoDB index effectively in production?
body: <p>I've been looking at MongoDB.  Feels good.</p>
  
  <p>I added some indexes to a collection, uploaded a bunch of data, then removed all the data, and I noticed the indexes did not change size, similar to the behavior reported <a href="https://stackoverflow.com/questions/1745812/two-questions-about-mongodb-and-indexing/1746901#1746901">here</a>.</p>
  
  <p>If I call</p>
  
  <pre><code>db.repairDatabase()
  </code></pre>
  
  <p>the indexes are then squashed to near-zero.    Similarly if I don't remove all the data, but call repairDatabase(), the indexes are squashed somewhat (perhaps because unused extends are truncated?).  I am getting index size from "totalIndexSize" of db.collection.stats().</p>
  
  <p>However, that takes a long time (I've read it could be hours on a large database).  It's unclear to me how available the database is for reads or writes while it is running.  I am guessing not so available.</p>
  
  <p>Since I want to run as few instances of mongod as possible, I want to understand more about how indexes are managed after deletes.  Can anyone point me to anything or give any advice?</p>