title: Guaranteeing sort order with an IAsyncCursor query?
body: <p>I'm using a collection with millions of records populated asynchronously, so there is no guarantee of order. </p>
  
  <p>When querying the MongoDB FindAsync method will allow a filter to be added, but not a sort.</p>
  
  <p>How do I ensure the order of records returned using IAsyncCursor?  I have an ascending index on a epoch date-stamp field in my collection, is that enough to guarantee the sort order?.</p>
  
  <p>====================</p>
  
  <p>An IAsyncCursor is returned by the FindAsync method. The records are returned in arbitrary batches which are processed using the following using using/while construct.</p>
  
  <pre><code>var collection = _database.GetCollection&lt;BsonDocument&gt;("restaurants");
  var filter = new BsonDocument();
  var count = 0;
  using (var cursor = await collection.FindAsync(filter))
  {
      while (await cursor.MoveNextAsync())
      {
          var batch = cursor.Current;
          foreach (var document in batch)
          {
              // What order will these records be in? how do I guarantee order ascending by epochtimestamp?;
          }
      }
  }
  </code></pre>
  
  <p>Will each async "batch" be sorted with respect to the entirety of the query? How do I guarantee records will be in the correct order?.</p>
  
  <p>The ascending index on the epocdatestamp field would allow me to return a full sorted list(Takes a very long time because of the number of records).  </p>
  
  <p>Should I one time rewrite that full sorted list back to the DB in the order I need to guarantee? So that future IAsyncCursor querys will return records in order. </p>
  
  <p>Do I need to do that? or is the ascending index enough?  </p>