如何在Spring Mongo数据中使用查找和管道进行聚合

时间:2019-10-16 07:37:22

标签: java spring mongodb

我是居住在韩国的开发商。 请理解我的英语不好。

如何将以下MongoDB查询转换为Java Spring应用程序要使用的查询?我找不到通过提供的查找方法使用管道的方法。

我尝试过这种方法,但是没有用。

Spring Data MongoDB Lookup with Pipeline Aggregation

db.component_class.aggregate(
[
    {
        $match: {superior_id: '5d64ab6e2a41be4f74cf12d7'}
    },
    {
        $lookup: {
            from:'component',
            let: {cc_id: '$_id'}, 
            pipeline: [
                {'$addFields': {'component_class_id': {'$toObjectId': '$component_class_id'}}},     
                {'$match': {'$expr': {'$eq': ['$component_class_id', '$$cc_id']}}},                 
                {
                    '$lookup': {
                        from: 'sensor',
                        let: {c_id: '$_id'},
                        pipeline: [
                            {'$addFields': {'component_id': {'$toObjectId': '$component_id'}}},
                            {'$match': {'$expr': {'$eq': ['$component_id', '$$c_id']}}}
                        ],
                        as: 'sensor_docs'
                    }
                }

            ],
            as: 'component_docs'
        }
    }
]
)

0 个答案:

没有答案