聚合管道$ graphLookup结果是其他集合的引用值。我想填充价值

时间:2018-03-08 08:42:34

标签: node.js mongodb express mongoose

此处aTrips具有属性bills的对象,这些对象引用其他集合数据。我想填充这些数据。

如何填充账单?

  let aFleetOwnerTripData = await RegisteredVehicleModel.aggregate( 
   [ { $match:{clientId:req.user.clientId,"owner_group":{$exists:true}} },
     { $group:{_id:"$owner_group",aVehicle: {$push: "$vehicle_reg_no"},count : {$sum : 1}} }, 
     { $graphLookup: { 
       from: "tripv2", 
       startWith: "$aVehicle", 
       connectFromField: "aVehicle", 
       connectToField: "vehicle_no", 
       as: "aTrips", 
      restrictSearchWithMatch: {
       "clientId" : req.user.clientId, 
       "statuses":{ 
         $elemMatch:{ status:status, date:{ "$gte": startDate, "$lte": currentDate } } 
       } 
     } 
    } } ] 
);

0 个答案:

没有答案