title: Mongodb an object representing an expression must have exactly one field when using $cond, $size and $in in aggregation pipeline
body: <p>I'm trying to work out for each country how many times the UK appears with the following query:</p>
  <pre><code>    db.movies.aggregate([
      {$unwind:&quot;$countries&quot;},
      {$group:{_id:&quot;$countries&quot;, total : { $sum: {$cond: [ {
      &quot;countries&quot;: {&quot;$in&quot; : [&quot;UK&quot;, [&quot;$countries&quot;]], &quot;$not&quot; : { &quot;$size&quot; : 1.0}}}, 1, 0]}}}},
      {$match: { total: { $gte: 10 }}}
      ])
  </code></pre>
  <p>which gives me an object representing an expression must have exactly one field: { $in: [ &quot;UK&quot;, [ &quot;$countries&quot; ] ], $not: { $size: 1.0 } }&quot;, although when I try the part giving me problems just by itself with a find it works fine:</p>
  <pre><code>db.movies.find(
  { &quot;countries&quot; : { &quot;$in&quot; : [&quot;UK&quot;, [&quot;$countries&quot;]], &quot;$not&quot; : { &quot;$size&quot; : 1}}}, 
  { &quot;_id&quot; : 0, &quot;countries&quot; : 1});
  </code></pre>
  <p>result:</p>
  <pre><code>{ &quot;countries&quot; : [ &quot;UK&quot;, &quot;New Zealand&quot; ] }
  { &quot;countries&quot; : [ &quot;USA&quot;, &quot;UK&quot; ] }
  { &quot;countries&quot; : [ &quot;UK&quot;, &quot;USA&quot;, &quot;France&quot; ] }
  { &quot;countries&quot; : [ &quot;UK&quot;, &quot;USA&quot; ] }
  { &quot;countries&quot; : [ &quot;USA&quot;, &quot;UK&quot; ] }
  { &quot;countries&quot; : [ &quot;UK&quot;, &quot;Italy&quot; ] }...
  </code></pre>