title: Mongodb Index Creation only if not already exists
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.
  I am thinking of using this, will it work:</p>
  
  <pre><code>if(db.collection.getIndexes().find({'name':'index_name'}).count()==0) { 
      db.collection.createIndex( { abc: 1, def: 1 } , { name: "index_name" } ) 
  }
  </code></pre>
  
  <p>or, there is any better way to do this ?
  Also if above code is wrong, please help me with this task.</p>