title: MongoDB Aggregation. Check if nested array contains value
body: <p>I have such fields in entity:</p>
  
  <pre><code>private String userId;
  private String username;
  private Date created;
  private List&lt;Comment&gt; comments = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p><code>Comment</code> have such fields :</p>
  
  <pre><code>private String userId;
  private String username;
  private String message;
  private Date created;
  </code></pre>
  
  <p>I need to make aggregation, and receive something like this :</p>
  
  <pre><code>{
    "userId" : "%some_userId%",
    "date" : "%some_date%",
    "commentsQty" : 100,
    "isCommented" : true
  }
  </code></pre>
  
  <p>My aggregation looks like this:</p>
  
  <pre><code>{ "aggregate" : "%entityName%" , "pipeline" : [
     { "$project" : { 
                "username" : 1 , 
                "userId" : 1 , 
                "created" : 1 , 
                "commentQty" : { "$size" : [ "$comments"]}}}]}
  </code></pre>
  
  <p>And it's working fine. But i need also to check, IF comments array contains some comment, with specific userId. I tried this one, but it fails to execute: </p>
  
  <pre><code>{ "aggregate" : "%entityName%" , "pipeline" : [
     { "$project" : { 
                "username" : 1 , 
                "userId" : 1 ,
                "created" : 1 , 
                "commentQty" : { "$size" : [ "$comments"]} ,
                "isCommented" : { "$exists" : [ "$comments.userId" , "5475b1e45409e07b0da09235"]}}}]}
  </code></pre>
  
  <p>with such message : <code>Command execution failed:  Error [exception: invalid operator '$exists']</code></p>
  
  <p>How such check can be done?</p>
  
  <p><strong>UPD:</strong> Also tried operators <code>$in</code> and similar, but they valid for queering, not for aggregation.</p>