title: MongoDB: Removing all collections whose name matches a string
body: <p>I've restructured my database a bit, and no longer have need for certain collections. However, there are far too many of them to remove by-hand (thousands, actually). Each of the collections in question begins with "cache_" and contains a couple of indexes which I'd like to make sure are completely cleaned up.</p>
  
  <p>I'm trying to understand how to use the mongo shell in order to loop over all collection names and remove those collections which begin with "cache_". Per the <a href="http://www.mongodb.org/display/DOCS/Queries+and+Cursors" rel="noreferrer">Queries &amp; Cursors documentation</a>, I understand how to loop over documents within a collection, but not how to use the MongoDB shell to loop through the collections in the database.</p>
  
  <p>In pseudo-code, this is what I need:</p>
  
  <pre><code>var all_collections = show collections
  for(var collection in all_collections)
      if(collection.name.indexOf('cache_')==0)
          collection.drop()
  </code></pre>
  
  <p>FWIW, I've done searching for "mongodb loop through collection names" etc. and have not found anything, but maybe I sux at teh googlez =P</p>
  
  <p>On a related note... after doing this degree of restructuring, should I be doing a <code>db.repairDatabase()</code> or anything of the sort in order to make sure the dropped indexes etc. are all nice and clean?</p>
  
  <p>Thanks.</p>