1

I am a developer living in Korea. Please understand my poor English.

How would I convert the following MongoDB query into a query to be used by my Java Spring application? I can't find a way to use pipeline with the provided lookup method.

I've tried this method, but it's no use.

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'
        }
    }
]
)
Joker2289
  • 11
  • 1
  • For your information, the version in use is 3.8.2 – Joker2289 Oct 16 '19 at 07:43
  • https://stackoverflow.com/questions/51107626/spring-data-mongodb-lookup-with-pipeline-aggregation – Joker2289 Oct 16 '19 at 07:44
  • I've already tried writing about it, but there's a problem with the transformation during the CustomAgregationOperation process. – Joker2289 Oct 16 '19 at 07:47
  • java.lang.ClassCastException: org.bson.Document cannot be cast to com.mongodb.DBObject at module.model.CustomAggregationOperation.toDBObject(CustomAggregationOperation.java:19) – Joker2289 Oct 16 '19 at 07:47

0 Answers0