title: MongoDb c# Linq query and return a collection's child objects
body: <p>Say I have a typical customers and orders scenario. I have a collection of customers and each customer document has a list of orders. Now I want to query the customers where the order date is within the last week, i.e. is greater than DateTime.UtcNow.AddDays(-7) and less than DateTime.UtcNow.</p>
  
  <pre><code>var startDate = DateTime.UtcNow.AddDays(-7);
  var endDate = DateTime.UtcNow;
  var query = collection.AsQueryable&lt;Customer&gt;()
      .Where(c =&gt; c.Orders.Any(o =&gt; o.OrderDate &gt; startDate &amp;&amp; o.OrderDate &lt; endDate))
      .SelectMany(b =&gt; b.Orders);
  </code></pre>
  
  <p>This results in the following error:</p>
  
  <pre><code>System.NotSupportedException: The SelectMany query operator is not supported.
  at MongoDB.Driver.Linq.SelectQuery.TranslateMethodCall(MethodCallExpression methodCallExpression) in C:\\build\\mongo-csharp-driver\\Driver\\Linq\\Translators\\SelectQuery.cs:line 687
  </code></pre>
  
  <p>My current solution is pretty nasty:</p>
  
  <pre><code>var customers =
      collection.AsQueryable&lt;Customer&gt;()
          .Where(c =&gt; 
              c.Orders.Any(o =&gt; 
                  o.OrderDate &gt; startDate &amp;&amp; 
                  o.OrderDate &lt; endDate))
          .ToList();
  
  var results = new List&lt;Order&gt;();
  foreach (var orders in customer.Select(c =&gt; 
      c.Orders.Where(o =&gt; 
          o.OrderDate &gt; startDate &amp;&amp; 
          o.OrderDate &lt; endDate)))
  {
      results.AddRange(orders);
  }
  
  return results;
  </code></pre>
  
  <p>Is there a better way to achieve this?</p>