title: Why Doctrine2 ODM's results of findBy() and createQueryBuilder()->getQuery()->execute() differ from each other?
body: <p>I have tried two different ways to do the same query with Doctrine's MongoDB-ODM.</p>
  
  <p>Can you figure out that why the two, in my opinion similar queries both return different result? Snippet 1 doesn't return anything where Snippet 2 returns correct database entries. Both of the queries seem similar in the log file - except #1 does not have skip &amp; limit lines.</p>
  
  <p><strong>Snippet 1</strong></p>
  
  <pre><code>$dateDayAgo = new \DateTime('1 day ago');
  $recentLogins = $this-&gt;get('user_activity_tracker')-&gt;findBy(array(
        'targetUser' =&gt; $userAccount-&gt;getId(),
        'code' =&gt; array('$in' =&gt; array('login.attempt','login.ok')),
        'ts' =&gt; array('$gte', $dateDayAgo)
      ))-&gt;sort(['ts' =&gt; 1]);
  </code></pre>
  
  <p>Symfony's log entries from the Snippet 1:</p>
  
  <pre><code>[2012-08-13 09:14:33] doctrine.INFO: MongoDB query: { "find": true, "query": { "targetUser": ObjectId("4fa377e06803fa7303000002"), "code": { "$in": [ "login.attempt", "login.ok" ] }, "ts": [ "$gte", new Date("Sun, 12 Aug 2012 09:14:33 +0000") ] }, "fields": [ ], "db": "eventio_com", "collection": "ActivityEvent" } [] []
  [2012-08-13 09:14:33] doctrine.INFO: MongoDB query: { "sort": true, "sortFields": { "ts": 1 }, "query": { "targetUser": ObjectId("4fa377e06803fa7303000002"), "code": { "$in": [ "login.attempt", "login.ok" ] }, "ts": [ "$gte", new Date("Sun, 12 Aug 2012 09:14:33 +0000") ] }, "fields": [ ] } [] []
  </code></pre>
  
  <p><strong>Snippet 2</strong></p>
  
  <pre><code>$recentLoginsQuery = $this-&gt;get('user_activity_tracker')-&gt;createQueryBuilder()
          -&gt;field('targetUser')-&gt;equals($userAccount-&gt;getId())
          -&gt;field('code')-&gt;in(array('login.attempt','login.ok'))
          -&gt;field('ts')-&gt;gte($dateDayAgo)
          -&gt;sort('ts','asc')
          -&gt;getQuery();
  
  $recentLogins = $recentLoginsQuery-&gt;execute();
  </code></pre>
  
  <p>Log entries for Snippet 2:</p>
  
  <pre><code>[2012-08-13 09:17:30] doctrine.INFO: MongoDB query: { "find": true, "query": { "targetUser": ObjectId("4fa377e06803fa7303000002"), "code": { "$in": [ "login.attempt", "login.ok" ] }, "ts": { "$gte": new Date("Sun, 12 Aug 2012 09:17:30 +0000") } }, "fields": [ ], "db": "eventio_com", "collection": "ActivityEvent" } [] []
  [2012-08-13 09:17:30] doctrine.INFO: MongoDB query: { "limit": true, "limitNum": null, "query": { "targetUser": ObjectId("4fa377e06803fa7303000002"), "code": { "$in": [ "login.attempt", "login.ok" ] }, "ts": { "$gte": new Date("Sun, 12 Aug 2012 09:17:30 +0000") } }, "fields": [ ] } [] []
  [2012-08-13 09:17:30] doctrine.INFO: MongoDB query: { "skip": true, "skipNum": null, "query": { "targetUser": ObjectId("4fa377e06803fa7303000002"), "code": { "$in": [ "login.attempt", "login.ok" ] }, "ts": { "$gte": new Date("Sun, 12 Aug 2012 09:17:30 +0000") } }, "fields": [ ] } [] []
  [2012-08-13 09:17:30] doctrine.INFO: MongoDB query: { "sort": true, "sortFields": { "ts": 1 }, "query": { "targetUser": ObjectId("4fa377e06803fa7303000002"), "code": { "$in": [ "login.attempt", "login.ok" ] }, "ts": { "$gte": new Date("Sun, 12 Aug 2012 09:17:30 +0000") } }, "fields": [ ] } [] []
  </code></pre>
  
  <p>My 'user_activity_tracker' service works just as a proxy to the underlying Doctrine repository / document manager. Both snippets get a LoggableCursor back after query.</p>