title: Find documents with arrays not containing a document with a particular field value in MongoDB
body: <p>I'm trying to find all documents that do not contain at least one document with a specific field value.  For example here is a sample collection:</p>
  
  <pre><code>{  _id : 1,
    docs : [
          { foo : 1,
            bar : 2},
          { foo : 3,
            bar : 3}
           ]
  },
  {  _id : 2,
    docs : [
          { foo : 2,
            bar : 2},
          { foo : 3,
            bar : 3}
           ]
  }
  </code></pre>
  
  <p>I want to find every record where there is not a document in the docs block that does not contain at least one record with foo = 1.  In the example above, only the second document should be returned.</p>
  
  <p>I have tried the following, but it only tells me if there are any that don't match (which returns document 1.</p>
  
  <pre><code>db.collection.find({"docs": { $not: {$elemMatch: {foo: 1 } } } })
  </code></pre>
  
  <p><strong>UPDATE:</strong> The query above actually does work. As many times happens, my data was wrong, not my code.</p>
  
  <p>I have also looked at the <a href="http://docs.mongodb.org/manual/reference/operator/nin/">$nin operator</a> but the examples only show when the array contains a list of primitive values, not an additional document.  When I've tried to do this with something like the following, it looks for the EXACT document rather than just the foo field I want.</p>
  
  <pre><code>db.collection.find({"docs": { $nin: {'foo':1 } } })
  </code></pre>
  
  <p>Is there anyway to accomplish this with the basic operators?</p>