Mongodb聚合左集合中的查找字段

时间:2018-07-09 07:04:59

标签: mongodb aggregate lookup

我在下面查询

db.firstcollection.aggregate([{
    $match: {
      organization: "org 1"
    }
  },
  {
    $lookup: {
      from: "secondcollection",
      localField: "id",
      foreignField: "id",
      as: "secondcollection"
    }
  },
  {
    "$unwind": "$secondcollection"
  },
  {
    $project: {
      id: "$secondcollection.id",
      col1: "ddd",
      "emailAddress": "$secondcollection.emailAddress",
      "fullName": "$secondcollection.fullName"
    }
  }
])

使用别名secondcollection,我们可以检索第二个集合的文件,但是如何从第一个集合中检索字段

谢谢

0 个答案:

没有答案