title: MongoDB array of objects
body: <p>The problem I am facing is below:</p>
  <p>I have a MongoDB document whose structure is as follows</p>
  <pre><code>&quot;name&quot;: &quot;XYZ&quot;,
  &quot;array&quot;:[
   {
    &quot;value&quot;: &quot;Alpha&quot;
   },
   {
    &quot;value&quot;: &quot;Beta&quot;
   },
   {
    &quot;value&quot;: &quot;Alpha&quot;
   },
  ]
  </code></pre>
  <p>and I have to count how many objects have value Alpha.
  I have tried the following two queries but both only give me value 1.</p>
  <pre><code>db.current_database.find({array: {$elemMatch: {value: &quot;Alpha&quot;}}}).count()
  db.current_database.find({'array.value': 'Alpha'}).count()
  </code></pre>