title: How can I get a subset of results in MongoDB C# Driver?
body: <p>I have a collection of versioned documents ("rHistory"), with this structure:</p>
  
  <pre><code>    {
          "rid": "123e",
          "v": 1
      },
      {
          "rid": "143fe",
          "v": 1
      },
      {
          "rid": "143fe",
          "v": 2
      },
      {
          "rid": "143fe",
          "v": 3
      },
      {
          "rid": "123e",
          "v": 2
      }
  </code></pre>
  
  <p>I'm writing a function to return a subset of the documents in this collection. Currently I find all matching items as follows:</p>
  
  <p><code>_rHistory.Find(r =&gt; rIds.Contains(r.RId)).ToList()</code></p>
  
  <p>However, I only want to return the highest versioned item of each result, like so:</p>
  
  <pre><code>    {
          "rid": "143fe",
          "v": 3
      },
      {
          "rid": "123e",
          "v": 2
      }
  </code></pre>
  
  <p>How can I find the newest version of each document matching a filter on rid and return the result as a list? I'm assuming aggregation is involved but I'm having trouble finding relevant examples. Obviously I'd rather not do this:</p>
  
  <pre><code>foreach (var rId in rIds)
  {
      res.Add(_rHistory.Find(r =&gt; r.RId == rId).SortByDescending(f =&gt; f.Version).FirstOrDefault());
  }
  </code></pre>