Mongodb 使用lookUp

 

db.getCollection('ShortProduct').aggregate([{
  $lookup: {
    from: "ShortProductPlans",
    localField: "_id",
    foreignField: "productId",
    as: "plan"
  }
}, {
  $unwind: "$plan"
}, {
  $addFields: {  planCode: "$plan.planCode",planName:"$plan.productPlanName" }
  }, {
        $match:{"productStatus":1,"_id":{"$in":["xxxxxxxxxxx"]}}
      },{
  $project: {
    _id: 1,
    productFullName: 1,
    planCode: 1,
    planName: 1
  }
}]);

 

 

posted @ 2020-03-24 09:31  地球上的我  阅读(1504)  评论(0编辑  收藏  举报