我正在尝试在 spring mongo 层上重新创建此查询。
db.LASTVIEWED_TEST.aggregate([{$match: {'_id' : '12070'}},
{$unwind:"$value"},
{$match:{"value.Dockey":{"$in":["390", "539","626"]}}},
{$group:{_id:"$_id", "value":{$push:"$value"}}}
])
我使用各种方法进行了一些尝试,但是我在这里遇到了示例:
并创建了这个:
Aggregation agg = Aggregation.newAggregation(//
match(where("entityid").is(entityId)),//
unwind("$value"), //
match(where("value.Dockey").in(dockeyList)),//
group("id").push("$value").as("value")//
);
但是这个构建器看不到识别 where、unwind 关键字等...并且我的编译器告诉我我的类没有这些方法。
我需要做什么才能将值传递给 newAggregation 构建器。
干杯,
最佳答案
您需要指定Criteria
匹配中的对象,通常所有值都只表示为字符串:
Aggregation agg = newAggregation(
match(Criteria.where("entityid").is(entityId)),
unwind("value"),
match(Criteria.where("value.Dockey").in(dockeyList)),
group("_id").push("value").as("value")
);
关于java - Spring mongo 上的聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26666575/