MongoDB自连接并仅从文档数组中选择子项

MongoDB自连接并仅从文档数组中选择子项,mongodb,mongodb-query,aggregation-framework,Mongodb,Mongodb Query,Aggregation Framework,我有如下数据 [ { "_id": 1, "members": [ "a1", "a2" ], "member_profiles": [ { "_id": "a1", "is_removed": true } ]

我有如下数据

[
  {
    "_id": 1,
    "members": [
      "a1",
      "a2"
    ],
    "member_profiles": [
      {
        "_id": "a1",
        "is_removed": true
      }
    ]
  },
  {
    "_id": 2,
    "members": [
      "a1",
      "a3"
    ],
    "member_profiles": [
      {
        "_id": "a3",
        "is_removed": true
      }
    ]
  }
]
我只想从文档中选择那些未删除
的成员

因此,上面的查询应该给出第一个文档中的
[“a2”]
,以及第二个文档中的
[“a1”]

最后,我想通过分组将所有这些成员ID放在一个集合中,但我一直在研究如何进行文档级过滤

提前感谢演示-


输出

[
  {
    "_id": 2,
    "activeMembers": [
      "a1"
    ]
  },
  {
    "_id": 1,
    "activeMembers": [
      "a2"
    ]
  }
]

看起来很紧张。谢谢你的帮助和帮助explaination@Manish很高兴我能帮忙:)
[
  {
    "_id": 2,
    "activeMembers": [
      "a1"
    ]
  },
  {
    "_id": 1,
    "activeMembers": [
      "a2"
    ]
  }
]