title: Mongodb - Array containing element and not containing another one
body: <p>I'm trying to query one of my mongodb collection that looks like this:</p>
  
  <pre><code>&gt; db.collection.find()
  {name: "foo", things: [{stuff:"banana", value: 1}, {stuff:"apple", value: 2}, {stuff:"strawberry", value: 3}]}
  {name: "bar", things: [{stuff:"banana", value: 4}, {stuff:"pear", value: 5}]}
  ...
  </code></pre>
  
  <p>My goal is to list all the object that have the <code>things</code> field containing an element with <code>stuff=banana</code> but no <code>stuff=apple</code></p>
  
  <p>I tried something like this:</p>
  
  <pre><code>db.transactions.find({
    "things": {
      $elemMatch: {
        "stuff": "banana", 
        $ne: {
          "stuff": "apple"
        }
      }
    }
  )
  </code></pre>
  
  <p>But it's not working. Any ideas?</p>