title: MongoDB filter an array field by period (start date, end date) using PHP
body: <p>I have MongoDB documents with this structure:</p>
  
  <pre><code>{
       _id: 1
       dates: [
           ISODate ("2015-08-21T22: 00: 00Z")
           ISODate ("2015-09-27T22: 00: 00Z")
       ],
       ...
  }
  </code></pre>
  
  <p>In my example, we see that the document 1 was accessed:</p>
  
  <ul>
  <li>2015-08-21</li>
  <li>2015-09-27</li>
  </ul>
  
  <p>In my application, I can filter by time period (start date, end date).</p>
  
  <p>If in my application I filter the period "2015-09-01 - 2015-09-01":</p>
  
  <p>Logically the document 1 should not be found because it was not consulted during this period. But with my tests, the document 1 is found.</p>
  
  <p>What conditions must I use to filter the data correctly?</p>
  
  <p>I tried that but it's fallible:</p>
  
  <pre><code>&lt;?php
  $begin = new \DateTime('2015-09-01');
  $end = new \DateTime('2015-09-01');
  
  $expr1 = $qb-&gt;expr()-&gt;field('dates')-&gt;gte($begin);
  $expr2 = $qb-&gt;expr()-&gt;field('dates')-&gt;lte($end);
  
  $qb
      -&gt;addAnd($expr1)
      -&gt;addAnd($expr2)
      ;
  </code></pre>
  
  <p>Thanks for your help,
  Yohann</p>