title: MongoDB: How to count number of values in key
body: <p>I'm very new to MongoDB and I need help figuring out how to perform aggregation on a key in MongoDB and use that result to return matches.</p>
  <p>For example, if I have a collection called Fruits with the following documents:</p>
  <pre><code>{
      &quot;id&quot;: 1,
      &quot;name&quot;: &quot;apple&quot;,
      &quot;type&quot;: [
        &quot;Granny smith&quot;,
        &quot;Fuji&quot;
      ]
    }, {
      &quot;id&quot;: 2,
      &quot;name&quot;: &quot;grape&quot;,
      &quot;type&quot;: [
        &quot;green&quot;,
        &quot;black&quot;
      ]
    }, {
      &quot;id&quot;: 3,
      &quot;name&quot;: &quot;orange&quot;,
      &quot;type&quot;: [
        &quot;navel&quot;
      ]
    }
  </code></pre>
  <p>How do I write a query that will return the names of the fruits with 2 types, ie apple and grape?</p>
  <p>Thanks!</p>