title: MongoDB/doctrine: can't nest $or in $and
body: <p>I'm having trouble nesting multiple two-operand <code>$or</code> operations within an <code>$and</code> operation. The conclusion of <a href="https://groups.google.com/d/topic/doctrine-user/fVkPvHZwQAE/discussion" rel="noreferrer">this discussion</a> sounds similar what I need, but I'm unable to get it to work. Here's JavaScript of what I'm trying to do:</p>
  
  <pre><code>db.Business.find(
    {
      $and:
        [
          { $or: [{nm: /American/}, {dsc: /American/}] },
          { $or: [{nm: /Mega/}, {dsc: /Mega/}] }
        ]
    }
  )
  </code></pre>
  
  <p>That works in the MongoDB interactive shell.</p>
  
  <p>And here's some PHP that looks ok to me but doesn't work (causes infinite recursion where indicated):</p>
  
  <pre class="lang-php prettyprint-override"><code>$q = $doctrineOdm-&gt;createQueryBuilder('Business');
  foreach (array('American','Mega') as $keyword) {
    $r = new \MongoRegex('/'.$keyword.'/i');
    $q-&gt;addAnd(
      $q-&gt;addOr($q-&gt;expr()-&gt;field('nm')-&gt;equals($r))
        -&gt;addOr($q-&gt;expr()-&gt;field('dsc')-&gt;equals($r))
    );
  }
  print_r($q-&gt;getQuery()-&gt;getQuery()); // infinite recursion
  $cursor = $q-&gt;getQuery()-&gt;execute();
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p><a href="https://groups.google.com/d/topic/doctrine-user/y5VqSEfB9Es/discussion" rel="noreferrer">Crossposted here</a>.</p>