title: How to find the all subdocuments contains particular key through $setDifference?
body: <p>Per comments of this question <a href="https://stackoverflow.com/questions/35451009/find-documents-with-arrays-that-contain-a-document-with-a-particular-field">Find documents with arrays that contain a document with a particular field</a>, <code>$setDifference</code> and <code>$map</code> should solve this issue. Here is the details of this question.</p>
  
  <blockquote>
    <p>I want to find only documents that have <strong>all</strong> <code>'docs.foo'</code> present in a array <code>docs</code>. Given the two documents as below</p>
  
  <pre><code>{  
      _id : 1,
      docs : [
          { bar : 2},
          { foo : 3, bar : 3}
      ]
  },
  {  
      _id : 2,
      docs : [
          { foo : 2, bar : 2},
          { foo : 3, bar : 3}
      ]
  } 
  </code></pre>
  </blockquote>
  
  <p>Here are my codes</p>
  
  <pre><code>db.collection.aggregate([ 
      {$project: {
          docs: {$setDifference: 
                  [{$map:
                      {input: '$docs', 
                      as: 'item', 
                      in: {$cond: [{$ne: [
                                      {$ifNull: ['$$item.foo', null]}, 
                                      null]}, 
                                 '$$item', 
                                 null]}}
                  }, 
                  [null]
                  ]
              }
      }}
  ])
  </code></pre>
  
  <p>However, the result is</p>
  
  <pre><code>{  
      _id : 1,
      docs : [
          { foo : 3, bar : 3}
      ]
  },
  {  
      _id : 2,
      docs : [
          { foo : 2, bar : 2},
          { foo : 3, bar : 3}
      ]
  } 
  </code></pre>
  
  <p>Only the <code>{bar: 2}</code> is removed from <code>_id: 1</code> document. I want the output is </p>
  
  <pre><code>{  
      _id : 1,
      docs : [ ]
  },
  {  
      _id : 2,
      docs : [
          { foo : 2, bar : 2},
          { foo : 3, bar : 3}
      ]
  } 
  </code></pre>
  
  <p>Is it possible to do that through <code>$setDifference</code>?</p>