Considering this set of data :
{
"lstLikeUserid" : ["5992dc5725ac203acfa101e6"],
"title" : "a title"
},
{
"lstLikeUserid" : ["6000dc5725ac203acfa101e6"],
"title" : "another title"
}
I want to create a computed field to indicate that a user id is present in the array lstLikeUserid.
Here is the code i use which does not work :
String userId ="5992dc5725ac203acfa101e6";
ConditionalOperators.Cond condOperation =
ConditionalOperators.when(Criteria.where("lstLikeUserid").is(userId))
.then("true")
.otherwise("false");
ProjectionOperation projectOperation =
Aggregation.project().and(condOperation).as("like").andInclude("title");
Aggregation aggregation
= Aggregation.newAggregation(projectOperation);
AggregationResults<ChannelItemEntry> result = mongoTemplate
.aggregate(aggregation,ChannelItemEntry.class, ChannelItemEntry.class);
The computed field "like" is always false even if the user id matches.