title: MongoDB/PyMongo: Querying multiple criteria - unexpected results
body: <p>I have a collection where some of the objects feature an key <code>foo</code>. I now try to query for all objects that indeed have this key but not with the specific value <code>bar</code>. For this I use the following query:</p>
  
  <pre><code>collection.find({'foo': {'$exists': True}, 'foo': {'$ne': 'bar'}})
  </code></pre>
  
  <p>I thought that both criteria are connected via a logical AND. However, I get also objects that don't feature key <code>foo</code>. In fact, I get the same result when I just use the query</p>
  
  <pre><code>collection.find({'foo': {'$ne': 'bar'}})
  </code></pre>
  
  <p>On the other hans, if I use</p>
  
  <pre><code>collection.find({'foo': {'$exists': True}})
  </code></pre>
  
  <p>I correctly only get objects with <code>foo</code> but obvisouly all of them, so some of them have the value <code>bar</code>.</p>
  
  <p>How do I have to formulate my query to achieve my initial result? Is there a kind of order in which multiple criteria are tested? Do I explicitly specify the logical AND of both criteria?</p>