title: MongoDB: Count of matching nested array elements
body: <p>I've got a simple parent child object stored as a document in MongoDB.  Something simplistic like Order/OrderItems.  (Order has an array of OrderItem)</p>
  
  <p>What I'd like to do is query for a count of Order Items where they meet a set of criteria.</p>
  
  <p>Example: In Order "999" find out how many order items had a quantity of 3.  </p>
  
  <pre><code>db.collection.find( {OrderId:999, "OrderItems.QuantityOrdered":3} ).count();
  </code></pre>
  
  <p>The way this query works is it returns "1" because if it matches at least one OrderItem inside the array it will return the count of Orders matched.</p>
  
  <p>How can I query for how many "OrderItems" matched?:</p>