{ $match : {'_id': 1}},
{ $project: {'friendUserList': 1 }},
{ $unwind: "$friendUserList" },
{ $match : {'friendUserList.state': 'INIT'}},
{ $group: { _id: "result", count: { $sum: 1 }}}
);
Aggregation aggregation = newAggregation(
match(Criteria.where("_id").is(1)),
project("friendUserList"),
unwind("friendUserList"),
match(Criteria.where("friendUserList.state").is("INIT")),
group("friendUserList").count().as("count")
);
AggregationResults<User> result =
mongoOperations.aggregate(aggregation, "user", User.class);
return (long) result.getMappedResults().size();
0 意見:
張貼留言