exclude fields in $lookup aggregation

In mongodb 3.6 you can use projection ($project) inside $lookup pipeline… Something like this

db.User.aggregate([
  { "$match": { "userID":"1" }},
  { "$lookup":{
    "from": "Skill",
    "pipeline": [
      { "$match": { "languageID": "hindiid", "skillID": { "$in": [ "javaid","pythonid" ] }}},
      { "$project": { "_id": 0 }}
    ],
    "as": "skills"
  }}
])

Leave a Comment