Database

[{"reference":"ReferenceStr","subgroup":[{"#":1,"param":123},{"#":2,"param":456},{"#":3,"param":789}],"group":[{"#":1,"start":1,"end":2},{"#":2,"start":3,"end":3}],}]

Query

db.collection.aggregate([{"$unwind":"$group"},{/** input your group condition here*/$match:{"group.#":1}},{"$lookup":{"from":"collection","let":{"end":"$group.end"},"pipeline":[{"$unwind":"$subgroup"},{"$match":{$expr:{$and:[/** find the subgroup that matches your condition*/{$eq:["$$end","$subgroup.#"]}]}}}],"as":"selfLookup"}},{"$unwind":"$selfLookup"},{$project:{_id:0,reference:"$selfLookup.reference",var:"$selfLookup.subgroup.param"}}])

Result