title: mongoose aggregate and remove field if condition met
body: <p>I have a data model which occasionally has empty arrays. I'd like to return a query that removes the empty arrays. Here's what I have so far:</p>
  
  <pre><code>var query = Recipe.aggregate([
      { $match: {'sites': site}},
       { $project:{ 
          '_id':0,
          'data.coupons': 
            {
              $cond: {if:{ $exists: true, $not: {$size: 0} }, then:1, else:0} 
            } 
        }}
  ]);
  </code></pre>
  
  <p>Currently I'm returning the error <code>MongoError: exception: invalid operator '$exists'</code>. Is there another way to check for empty arrays? I'd like to keep the value if it meets the condition and reject it if it does not. </p>