【发布时间】:2017-07-28 04:55:47
【问题描述】:
这是我的数据
{"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" } }}
] );
我的问题是我想在spring数据下运行这段代码
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);
请给我一个提示来解决我的问题.... 提前致谢!
【问题讨论】:
-
我无法处理提交的条件。
标签: java mongodb mongodb-query spring-data aggregation-framework