如何以spring-data样式过滤嵌套的mongodb数组

我有一个game的文档结构,其中有一个rounds数组,每个回合都有一个用户的attends数组,每个参与者都有一个uid字段。像这样:

{
    rounds: [
        {
            attends: [
                {
                    uid:1
                },{
                    uid:2
                }
            ]
        },{
            attends: [
                {
                    uid:1
                },{
                    uid:2
                }
            ]
        }
    ]
}

现在,我要查询一个用户的出席数据。我知道如何使用shell这样查询此问题:

db.game.aggregate([
    { $project: {
        rounds: {
            $map: {
                input: "$rounds",as: "round",in: {
                    attends: {
                        $filter: {
                            input: "$$round.attends",as: "attend",cond: {
                                $eq: ["$$attend.uid",1]
                            }
                        }
                    }
                }
            }
        }
    }}
])

而且我知道如何使用mongo driver来实现这一点,只需将其一一转换为Java。

但是,我无法以spring-data样式实现等效代码:

Aggregation aggregation = Aggregation.newAggregation(
        Aggregation.project().and(VariableOperators.mapItemsOf(......
);
mongoTemplate.aggregate(aggregation,Game.class,Game.class);

有人可以帮助我如何以$filter样式实现$mapspring-data吗?

clshz2009 回答:如何以spring-data样式过滤嵌套的mongodb数组

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3098154.html

大家都在问