title: How to write a query for "orderby" in Mongo driver for C# to sort?
body: <p>I am trying to retrieve five recent documents from "Deal" collection in a MongoDB using C# driver for MongoDB. I can do it with the below code.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public IList&lt;TEntity&gt; GetRecentFive()
  {
      IList&lt;TEntity&gt; entities = new List&lt;TEntity&gt;();
      using (MongoDbContext dbContext = new MongoDbContext(_dbFactory))
      {
          var cursor = dbContext.Set&lt;TEntity&gt;().FindAll().SetSortOrder(SortBy.Descending("ModifiedDateTime")).SetLimit(5);
  
          foreach (TEntity entity in cursor)
          {
              entities.Add(entity);
          }
      }
  
      return entities;
  }
  </code></pre>
  
  <p>But I want to get only the recent 5 documents and FindAll() loads all the documents in the collection. I tried to do it with Find() but it needs a query as a parameter. How can I write a query for "orderby" in Mongo driver for C# to sort?</p>
  
  <p><a href="https://stackoverflow.com/a/2148479/778101">https://stackoverflow.com/a/2148479/778101</a> asked a similar question here. But the accepted answer doesn't work for me.</p>