我在MongoDB中有一个集合,它与另一个集合的关联字段如下所示:
的processError
{
id: "error-1",
error: "Error 1",
process: {"$ref": "col2", "$id": "Something"}
}
过程
{
id: "process-1",
title: "Hello"
}
我想通过ProcessError.process.id进行分组并获取ProcessError.process.title,我这样做了
Aggregation agg = Aggregation.newAggregation(
match(Criteria.where("process.id").in(processIds)),
group("process.id").count().as("total"),
project("total").and("title").previousOperation()
);
AggregationResults<Map> groupResults = mongoTemplate.aggregate(
agg,
ProcessError.class,
Map.class
);
但它返回整个ProcessError.process而不仅仅是ProcessError.process.title作为标题