I have such fields in entity:
private String userId;
private String username;
private Date created;
private List<Comment> comments = new ArrayList<>();
Comment have such fields :
private String userId;
private String username;
private String message;
private Date created;
I need to make aggregation, and receive something like this :
{
"userId" : "%some_userId%",
"date" : "%some_date%",
"commentsQty" : 100,
"isCommented" : true
}
My aggregation looks like this:
{ "aggregate" : "%entityName%" , "pipeline" : [
{ "$project" : {
"username" : 1 ,
"userId" : 1 ,
"created" : 1 ,
"commentQty" : { "$size" : [ "$comments"]}}}]}
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:
{ "aggregate" : "%entityName%" , "pipeline" : [
{ "$project" : {
"username" : 1 ,
"userId" : 1 ,
"created" : 1 ,
"commentQty" : { "$size" : [ "$comments"]} ,
"isCommented" : { "$exists" : [ "$comments.userId" , "5475b1e45409e07b0da09235"]}}}]}
with such message : Command execution failed: Error [exception: invalid operator '$exists']
How such check can be done?
UPD: Also tried operators $in and similar, but they valid for queering, not for aggregation.