Let say i have userInformation collection below structure
userInformation:
- name : String
- accounts[] : array
I need to covert below query into java springboot query.
db.userInformation.aggregate([{$match : {"name" : "madhu"}}, {$project: { "name": 1,
accountsCount: { $size:{ $filter: { input: "$accounts", as: "account", cond: {"$eq":["$$account.enabled", 0]}}}} }}]);
I have tried like below:
MatchOperation matchStage = Aggregation.match(new Criteria("name").is("madhu");
ProjectionOperation appProjectStage = Aggregation.project("name").
and(new AggregationExpression() {
@Override
public Document toDocument(AggregationOperationContext context) {
Document filterExpression = new Document();
filterExpression.put("input", "$accounts");
filterExpression.put("as", "account");
filterExpression.put("cond", new Document("$eq", Arrays.<Object> asList("$$account.enabled", 1)));
return new Document("$filter", filterExpression);
}
}).as("filterdAccounts");
From there I could not able to convert that as count. Any help is appropriated.
Thanks