title: C# MongoDB: Querying a $match on an array after an $unwind
body: <p>I have an aggregation pipeline to be performed using IAggregateFluent. </p>
  
  <p>Here is the class mapping with the DB</p>
  
  <pre><code>public class Card
      {
          public ObjectId Id { get; set; }
          public string CardNumber { get; set; }
          public string CustomerId { get; set; }
          public decimal BalanceAmount { get; set; }
          public string Currency { get; set; }
          public List&lt;CardTransaction&gt; Transactions { get; set; }
      }
  </code></pre>
  
  <p>And CardTransaction as</p>
  
  <pre><code>public class CardTransaction
      {
          //public ObjectId Id { get; set; }
          public DateTime TransactionDate { get; set; }
          public decimal InitialBalance { get; set; }
          public decimal FinalBalance { get; set; }
          public decimal TransactionAmount { get; set; }
          public string OrderNumber { get; set; } //Unique for every transaction
      }
  </code></pre>
  
  <p>How do I query to get only the CardTransaction (as a projection at the end) matching a particular OrderNumber using Fluent Aggregation.</p>
  
  <p>This works perfectly on the shell but translating it to C# doesnt seem to work without using BsonDocument</p>
  
  <pre><code>db.cards.aggregate([
      {
          $match:{
              CardNumber:"00000001"
          }
      },
      {
          $unwind:"$Transactions"
      },
      {
          $match:{
              "Transactions.OrderNumber":"123456789-1"
          }
      },
      {
          $project:{
              _id:0,
              Transactions:1
          }
      }
  ])
  </code></pre>
  
  <p>So far: </p>
  
  <pre><code>    Cards.Aggregate()
      .Match(x =&gt; x.CardNumber == someCardNumber)
      .Unwind&lt;Card,Card&gt;(x =&gt; x.Transactions)
      .Match(x =&gt; x.Transactions.MethodThatReturnsBool
  (y=&gt;y.OrderNumber == someOrderNumber))
      .Project(p=&gt;p.Transactions).ToList();
  </code></pre>