📜  MongoDB 聚合查找匹配数组 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:16.985000             🧑  作者: Mango

代码示例1
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"
  }}
])