0

I'm using mongodb and laravel to join two collections 'Course' and 'Course Objectives' using lookup but it is giving me error as: "$pipeline is not a list (unexpected index: "$lookup")". The code is:

$data = Course::raw(function($collection){
            return $collection->aggregate([
                '$lookup' =>[
                    'from'=> '$course_objectives',
                    'localField'=> 'id',
                    'foreignField' => 'course_id',
                    'as' => 'course_objective',
                ],
            ]);
        });
  • you are passing aggregate an object/map with a key named `$lookup`, shouldn't there be an array of objects? – Joe Jul 14 '20 at 11:34
  • The `$collection->aggregate(` function takes an array of stages. You are passing a single stage, not an array. – Joe Jul 14 '20 at 16:25

0 Answers0