title: Mongo Java-driver: recreation indexes after collection dropping
body: <p>I have a necessity to remove all data from mongo collection. Droping of collection works faster than <code>collection.remove(new BasicDBObject())</code>. But it also removes index definitions. Therefore I want to restore index definitions after collection dropping.</p>
  
  <p>In general I have following plan:</p>
  
  <ol>
  <li>Get all index definitions before dropping:
  <a href="http://www.mongodb.org/display/DOCS/Java+Tutorial#JavaTutorial-GettingaListofIndexesonaCollection" rel="nofollow">http://www.mongodb.org/display/DOCS/Java+Tutorial#JavaTutorial-GettingaListofIndexesonaCollection</a></li>
  <li>Recreate definitions after dropping: <a href="http://www.mongodb.org/display/DOCS/Java+Tutorial#JavaTutorial-CreatingAnIndex" rel="nofollow">http://www.mongodb.org/display/DOCS/Java+Tutorial#JavaTutorial-CreatingAnIndex</a></li>
  </ol>
  
  <p>The issue for me is exact value that should be retrieved/passed for index recreation. E.g. will following correct work for all types of indexes:</p>
  
  <pre><code>List&lt;DBObject&gt; storedDefinitions = coll.getIndexInfo();
  coll.drop();
  for (DBObject storedDefinition : storedDefinitions) {
    coll.createIndex(storedDefinition.get("key"));
  }
  </code></pre>
  
  <p>If no - what is the best way to achieve my goals?</p>
  
  <p>Thanks for any help! </p>