title: Query for a Document Nested in an Array using Doctrine mongodb odm
body: <p>I want to execute <a href="https://docs.mongodb.com/manual/tutorial/query-array-of-documents/" rel="nofollow noreferrer">Document Nested in an Array queries</a> with the <a href="http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/1.2.x/reference/query-builder-api.html" rel="nofollow noreferrer">Doctrine mongodb odm query builder</a></p>
  
  <p>I have basically a structure similar to : </p>
  
  <blockquote>
    <p>db.inventory.insertMany( [</p>
    
    <p>{ item: "journal", instock: [ { warehouse: "A", qty: 5 }, {
    warehouse: "C", qty: 15 } ] },</p>
    
    <p>{ item: "notebook", instock: [ { warehouse: "C", qty: 5 } ] },</p>
    
    <p>{ item: "postcard", instock: [ { warehouse: "B", qty: 15 }, {
    warehouse: "C", qty: 35 } ] } </p>
    
    <p>]);</p>
  </blockquote>
  
  <p>I want to execute this shell query within the query builder</p>
  
  <blockquote>
    <p>db.inventory.find( { "instock": { warehouse: "A", qty: 5 } } )</p>
  </blockquote>
  
  <p>I have tried this, but this won't work as it ignores the field 'instock'.</p>
  
  <blockquote>
    <p>$qb->field('instock')->field('warehouse')->equals('A')->field('qty')->equals(5)</p>
  </blockquote>
  
  <p>Keep in mind that doing the following</p>
  
  <blockquote>
    <p>$qb->field('instock.warehouse')->equals('A')->field('instock.qty')->equals(5)</p>
  </blockquote>
  
  <p>is a different logic (<a href="https://docs.mongodb.com/manual/tutorial/query-array-of-documents/#combination-of-elements-satisfies-the-criteria" rel="nofollow noreferrer">check second example</a>), because it matches not necessarily the same embedded document.</p>
  
  <p>I can implement it using $where and a loop, but it is ugly and slow. any better ideas ?</p>