title: How can I manage the disk size of a GridFS MongoDB database?
body: <p>I have a <code>GridFS MongoDB</code> database that I need to manage the size of. It has been running very well since it was created, but I have never really looked at its disk size until now.</p>
  
  <p>Judging by this outout from the <code>db.stats()</code> command</p>
  
  <pre><code>&gt; db.stats()
  {
      "db" : "documents",
      "collections" : 4,
      "objects" : 10967,
      "avgObjSize" : 52491.573994711405,
      "dataSize" : 575675092,
      "storageSize" : 595255296,
      "numExtents" : 24,
      "indexes" : 4,
      "indexSize" : 686784,
      "fileSize" : 2080374784,
      "nsSizeMB" : 16,
      "ok" : 1
  }
  </code></pre>
  
  <p>it seems the database itself is roughly 600MB. This size makes sense to me as it is the same size as the database backups I get from <code>mongodump</code>. The file size is far larger though, and it gets worse when I look in the data directory itself in <code>/var/lib/mongodb</code>:</p>
  
  <pre><code>root@deathstar:/var/lib/mongodb# ls -la
  total 2474036
  drwxr-xr-x  5 mongodb mongodb       4096 Apr 15 09:28 .
  drwxr-xr-x 62 root    root          4096 Mar  4 07:48 ..
  drwxr-xr-x  2 mongodb mongodb       4096 Apr 13 11:48 documents
  -rw-------  1 mongodb mongodb   67108864 Apr 15 09:16 documents.0
  -rw-------  1 mongodb mongodb  134217728 Apr 13 11:48 documents.1
  -rw-------  1 mongodb mongodb  268435456 Apr 13 11:48 documents.2
  -rw-------  1 mongodb mongodb  536870912 Apr 15 09:16 documents.3
  -rw-------  1 mongodb mongodb 1073741824 Apr 13 11:50 documents.4
  -rw-------  1 mongodb mongodb   16777216 Apr 15 09:16 documents.ns
  drwxr-xr-x  2 mongodb mongodb       4096 Apr 13 11:50 journal
  -rwxr-xr-x  1 mongodb mongodb          5 Apr 13 11:46 mongod.lock
  drwxr-xr-x  2 mongodb mongodb       4096 Apr 15 09:28 _tmp
  -rw-------  1 mongodb mongodb   67108864 Apr 15 09:28 -v.0
  -rw-------  1 mongodb mongodb   67108864 Apr 15 09:28 v.0
  -rw-------  1 mongodb mongodb  134217728 Apr 15 09:28 -v.1
  -rw-------  1 mongodb mongodb  134217728 Apr 15 09:28 v.1
  -rw-------  1 mongodb mongodb   16777216 Apr 15 09:28 -v.ns
  -rw-------  1 mongodb mongodb   16777216 Apr 15 09:28 v.ns
  </code></pre>
  
  <p>And this in <code>/var/lib/mongodb/journal</code>:</p>
  
  <pre><code>root@deathstar:/var/lib/mongodb/journal# ls -la
  total 3145752
  drwxr-xr-x 2 mongodb mongodb       4096 Apr 13 11:50 .
  drwxr-xr-x 5 mongodb mongodb       4096 Apr 15 09:28 ..
  -rw------- 1 mongodb mongodb 1073741824 Apr 15 09:28 j._2
  -rw------- 1 mongodb mongodb         88 Apr 15 09:28 lsn
  -rw------- 1 mongodb mongodb 1073741824 May  5  2012 prealloc.1
  -rw------- 1 mongodb mongodb 1073741824 May  5  2012 prealloc.2
  </code></pre>
  
  <p>Now correct me if I'm wrong, but I am basically looking at 5.5GB disk size for a 600MB database. That is pretty inefficient.</p>
  
  <p>How can I reduce the disk size? Is there a similar command to <code>OPTIMIZE TABLE</code> in <code>MySQL</code>? </p>
  
  <p>I don't know whether <code>GridFS</code> is a different beast from a regular database, but I tried running <a href="http://docs.mongodb.org/manual/reference/command/compact/" rel="nofollow">compact</a> but it didn't do anything to the disk size.</p>
  
  <p>And how about the journal files? Can I somehow reduce the disk size of all journal files?</p>