title: How to get first item from a grouped array in mongodb
body: <p>I've got a query and it works perfectly in shell</p>
  
  <pre><code>db.getCollection('chatmessages').aggregate(
  [
      { 
          $match : { 
              ChatId: { $in : [ObjectId("59edf7d34330cf25d6acd3fb")] }
          },
      },
      { 
          $group : { 
              _id : { ChatId : "$ChatId" },
              LastMessage : { $first : "$$CURRENT"}
          }
      }
  ])
  </code></pre>
  
  <p>But when I'm trying to make it work in c# like this:</p>
  
  <pre><code>        var list = await _mongoCollection.Aggregate()
              .Match(mes =&gt; chatIdsObject.Contains(mes.ChatId))
              .SortBy(mes =&gt; mes.ChatId)
              .ThenByDescending(mes =&gt; mes.CreateDateTime)
              .Group(
                  key =&gt; key.ChatId,
                  group =&gt; new
                  {
                      ChatId = group.Key,
                      LastMessage = group.Select(x =&gt; x).First()
                  })
              .ToListAsync();
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>$project or $group does not support {document}.</p>
  </blockquote>
  
  <p>Is there a way to make $first in cooperation with $$CURRENT work in C#?</p>