title: Is there a way to create or update a MongoDB index?
body: <p>According to the documentation on the <a href="http://docs.mongodb.org/manual/reference/command/createIndexes/" rel="nofollow noreferrer"><code>createIndexes</code> command</a>:</p>
  
  <blockquote>
    <p>If you create an index with one set of options and then issue createIndexes with the same index fields but different options, MongoDB will not change the options nor rebuild the index.</p>
  </blockquote>
  
  <p>The solution is to drop the index and create it from scratch, but that's costly.</p>
  
  <p>Is there a way to create an index when there isn't one, do nothing if there is an index with the same options, and replace the index if the options have changed?</p>
  
  <hr>
  
  <p>This question was originally raised by <a href="https://stackoverflow.com/users/1943129/phil-barresi">Phil Barresi</a> <a href="https://stackoverflow.com/questions/24811818/what-is-the-best-practice-to-ensure-a-mongodb-index-with-c-sharp-driver/24812176#24812176">here</a> but has since been deleted.</p>