這是我的數據總和聚集在MongoDB中使用Spring數據
{"intentId" : "A1", "like" : "Y"}
{"intentId" : "A1", "like" : "Y"}
{"intentId" : "A1", "like" : "N"}
{"intentId" : "A2", "like" : "Y"}
{"intentId" : "A2", "like" : "N"}
{"intentId" : "A2", "like" : "N"}
{"intentId" : "A2", "like" : "N"}
和mondodb腳本運行的非常好。這裏是代碼。
db.getCollection('test').aggregate([
{
$project:
{
intentId: 1,
likeY:
{
$cond: [ { $eq: [ "$like", "Y" ] }, 1, 0 ]
},
likeN:
{
$cond: [ { $eq: [ "$like", "N" ] }, 1, 0 ]
}
}
},
{ $group : { _id : "$intentId", likeY: { $sum: "$likeY" }, likeN: { $sum: "$likeN" } }}
]);
我的問題是,我想在春天的數據運行這段代碼
MatchOperation matchStage = Aggregation.match(new Criteria ("delYn").ne("Y"));
GroupOperation groupStage = Aggregation.group("intentId");
Cond operatorNbS = ConditionalOperators.when("like").then("Y").otherwise(value)
ProjectionOperation projectStage = Aggregation.p
SortOperation sortStage = Aggregation.sort(Sort.Direction.DESC, "_id");
Aggregation aggregation = Aggregation.newAggregation(matchStage, groupStage,projectStage,sortStage);
請給我一個提示,以解決我的問題.... 在此先感謝!
我不能韓dle條件提交。 – james