title: MongoDB C# Driver Create Index
body: <p>I just updated my MongoDB from version 2.5.0 to 2.7.0. Visual Studio tells me that the following way to create an index is obsolete:</p>
  <pre class="lang-cs prettyprint-override"><code>protected override Task OnPerformMaintenanceAsync(CancellationToken cancellationToken) 
      =&gt; NotificationLogs.Indexes
                         .CreateOneAsync(Builders&lt;NotificationLog&gt;.IndexKeys
                                                                  .Ascending(_ =&gt; _.TimestampUtc));
  </code></pre>
  <p>It suggests me to use <a href="https://mongodb.github.io/mongo-csharp-driver/2.6/apidocs/html/T_MongoDB_Driver_CreateIndexModel_1.htm" rel="noreferrer">CreateIndexModel</a>.</p>
  <p>The only problem is that I cannot find an example to get this working that will do the same.</p>
  <p>I tried:</p>
  <pre><code>protected Task OnPerformMaintenanceTestAsync(CancellationToken cancellationToken)
  {
    // Old approach
    var builder = Builders&lt;NotificationLog&gt;.IndexKeys
                                           .Ascending(x =&gt; x.TimestampUtc);
  
    // New approach
    var indexModel = new CreateIndexModel&lt;NotificationLog&gt;(nameof(NotificationLog.TimestampUtc));
    
    return NotificationLogs.Indexes.CreateOneAsync(indexModel);
  }
  </code></pre>
  <p>But I get the following exception:</p>
  <p><code>System.FormatException: 'JSON reader was expecting a value but found 'TimestampUtc'.'</code></p>