title: MongoDb Access array of objects with certain property
body: <p>I have one document as follows:</p>
  
  <pre><code>{
      user: 'hvt07',
      photos: [
      {
          link: 'http://link.to.com/image1.jpg',
          isPrivate: true
      },
      {
          link: 'http://link.to.com/image2.jpg',
          isPrivate: false
      }
      ]
  }
  </code></pre>
  
  <p>I want to get all photos which are with:</p>
  
  <pre><code>isPrivate: false
  </code></pre>
  
  <p>I am using the following query:</p>
  
  <pre><code>db.collection_name.find({ photos:{ $elemMatch:{isPrivate: false} } }).pretty()
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>db.collection_name.find({'photos.isPrivate': true}).pretty()
  </code></pre>
  
  <p>But both return all elements in the array even ones that are set as :</p>
  
  <pre><code>isPrivate: true
  </code></pre>
  
  <p>Please suggest.</p>