title: Checking if an Index exists in mongodb
body: <p>Is there a command that i can use via javascript in mongo shell that can be used to check if the particular index exists in my mongodb. I am building a script file that would create indexes. I would like that if I run this file multiple number of times then the indexes that already exists are not recreated.</p>
  
  <p>I can use db.collection.getIndexes() to get the collection of all the indexes in my db and then build a logic to ignore the ones that already exists but i was wondering if there is command to get an index and then ignore a script that creates the index. Something like:</p>
  
  <pre><code>If !exists(db.collection.exists("indexname")) 
  {
      create  db.collectionName.CreateIndex("IndexName")
  }
  </code></pre>