错误信息查找管道必须是字符串,是数组类型

Error message lookup pipeline must be a string, is type array

我正在使用 mongodb 3.6 版本。

我有车辆 table,文件如

   {
    "_id": ObjectId("5b976220d2ccda12fc0050fb"),
    "VehicleNumber": "JK 678",
    "NumberOfSeats": "47",
   }
   {
    "_id": ObjectId("67976220d2ccda12fc005068"),
    "VehicleNumber": "JK 779",
    "NumberOfSeats": "47",
   }

我有路线 table,数据如

    {
    "_id": ObjectId("5b7fb426d2ccda11fc005185"),
    "Name": "New Jersey City",
     "VehicleDetails": [
     {
        "VehicleEntryId": "b8d0d2b5-8f32-6850-4d79-34ed79138d6d",
        "VehicleId": ObjectId("5b976220d2ccda12fc0050fb"),
          ...
         "Status": "Active" 
      },
      {
      "VehicleEntryId": "b8d0d2b5-8f32-6850-4d79-34ed79138568",
      "VehicleId": ObjectId("67976220d2ccda12fc005068"),
        ...
       "Status": "Active" 
      } 
    ],
    ...
    }

我写了mongodb聚合查询像

       $cursor = $this->collection->aggregate([
    ['$match' => ["_id" => new MongoDB\BSON\ObjectID('5b7fb426d2ccda11fc005185')]],
    [
        '$addFields' => [
            'filteredIds' => [
                '$map' => [
                    'input' => '$VehicleDetails',
                    'as' => 'item',
                    'in' => [
                        '$cond' => [
                            ['$eq' => ['$$item.Status', 'Active']],
                            '$$item.VehicleId',
                            false
                        ]
                    ]
                ]
            ]
        ]
    ],

     array(
            '$lookup' => array(
                'from' => 'VehicleTbl',
                '$pipeline' => [
                       [ '$match'=> ["_id" => ['$in' => ['$$filteredIds'] ]]],
                 ],
                'as' => 'AllotedVehicleDetails'
            )
        ),
])->toArray();

基本上我正在尝试将所有指定的车辆提取到特定路线。因此,我首先使用 $addFeilds 运算符获取所有主动分配的车辆 ID,并将它们放入 "filteredIds" 中,然后在查找中我尝试使用管道从车辆 table 中获取车辆信息。上面的代码抛出错误消息 'Uncaught exception 'MongoDB\Driver\Exception\RuntimeException' with message '$lookup argument '$pipeline: [ { $match: { _id: { $in: [ "$$filteredIds" ] } } } ]' must be字符串,第 32 行中的数组类型。

请帮忙!!!

使用 pipeline 而不是 $pipeline

示例:

{
      $lookup : {
          'from' : 'vehicles',
           let : { localFilterIds : '$filteredIds'},
          pipeline : [
              {'$match'  : { $expr: {  '$in' : [ '$_id', '$$localFilterIds' ]  }} }
          ],
         'as' : 'AllotedVehicleDetails'
      }
  }

注意:这是在 mongoDb GUI Robo 3T.

中测试的