$project in $lookup mongodb

You can use $lookup 3.6 syntax to $project the fields inside the $lookup pipeline

User.aggregate([
  { "$lookup": {
    "from": "schedules",
    "let": { "id": "$_id.phone" },
    "pipeline": [
      { "$match": { "$expr": { "$eq": ["$customer.phone", "$$id"] }}},
      { "$project": { "scheduleStart": 1, "scheduleEnd": 1 }}
    ],
    "as": "user_detail"
  }}
])

Leave a Comment