Answers for "mongodb aggregate match in array of objects"

1

MongoDB Aggregation Lookup Match Array

db.users.aggregate([
  {"$match":{"_id":ObjectId(..)}},
  {"$lookup":{
    "from":"groups",
    "let":{"_id":"$_id"},
    "pipeline":[
      {"$match":{"$expr":{"$in":["$$_id","$members"]}}},
      {"$unwind":"$members"},
      {"$match":{"$expr":{"$eq":["$$_id","$members"]}}}
    ],
    "as":"members"
  }}
])
Posted by: Guest on June-01-2021

Code answers related to "mongodb aggregate match in array of objects"

Browse Popular Code Answers by Language