我有以下结构化集合
SharedMediaCollection:
{_id:111,
imageShared:{imageId:00234,
commentArea[{whoCommented:xyz,commentText:hi}, {whoCommented:yxz,commentText:hello}]}
};
现在我在commentArea上放松一下,并尝试展示whocommented以及他评论的内容。
我做了这样的代码...
Aggregation aggr = newAggregation(
unwind("imageShared.commentArea"),
project().andInclude("imageShared.commentArea.whoCommented"));
AggregationResults<TestAgree1> groupResults = mongoTemplate.aggregate(aggr,SharedMediaCollec.class,TestAgree1.class );
List<TestAgree1> result = groupResults.getMappedResults();
这里的SharedMediaCollec.class是我上面收集的结构化pojo类和 TestAgree1是我的烹饪pojo,它只保留CommentArea结构,因为我正在进行投影。
请让我知道我在做错的地方。我知道其他参考链接在那里但是我无法弄清楚在分配输出类型类时我正在做什么错误。
答案 0 :(得分:1)
我犯的错误是,我没有改变聚合结果的输出类型。 展开后,输入数组列表类型将更改为文档类型。我确实创建了另一个没有列表类型的实体对象。
全部谢谢 - :)