title: In Mongodb, how to retrieve the subset of an object that matches a condition?
body: <h3>What I'm trying to do:</h3>
  <p>Filter a field of a collection that matches a given condition. Instead of returning every item in the field (which is an array of items), I only want to see matched items.</p>
  <p>Similar to</p>
  <pre><code>select items from test where items.histPrices=[10,12]
  </code></pre>
  <p>It is also similar to what's found on the mongodb website here: <a href="http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields" rel="nofollow noreferrer">http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields</a></p>
  <p>Here's what I have been trying:</p>
  <pre><code>db.test.save({&quot;name&quot;:&quot;record&quot;, &quot;items&quot;:[{&quot;histPrices&quot;:[10,12],&quot;name&quot;:&quot;stuff&quot;}]})
  db.test.save({&quot;name&quot;:&quot;record&quot;, &quot;items&quot;:[{&quot;histPrices&quot;:[10,12],&quot;name&quot;:&quot;stuff&quot;}, 
  {&quot;histPrices&quot;:[12,13],&quot;name&quot;:&quot;stuff&quot;},{&quot;histPrices&quot;:[11,14],&quot;name&quot;:&quot;stuff&quot;}]})
  
  db.test.find({},{&quot;name&quot;:1,&quot;items.histPrices&quot;:[10, 12]})
  </code></pre>
  <p>It will return all the objects that have a match for items.histPrices:[10,12], including ALL of the items in items[]. But I don't want the ones that don't match the condition.</p>
  <p>From the comments left on Mongodb two years ago, the solution to get only the items with that histPrices[10,12] is to do it with javascript code, namely, loop through the result set and filter out the other items.</p>
  <p>I wonder if there's a way to do that with just the query.</p>