Database
db={CUSTOMER:[{"CID":"C1","CNAME":"Mark"},{"CID":"C2","CNAME":"Chris"},{"CID":"C3","CNAME":"James"}],ACCOUNT:[{"ANO":1,"Amount":1000,"CID":1},{"ANO":2,"Amount":350,"CID":2},{"ANO":3,"Amount":450,"CID":1},{"ANO":4,"Amount":360,"CID":3},{"ANO":5,"Amount":800,"CID":3}],TRANSACTIONS:[{"TID":"T1","ANO":1,"Amount":100,"TDATE":new Date("2005-03-22")},{"TID":"T2","ANO":3,"Amount":350,"TDATE":new Date("2005-03-22")},{"TID":"T3","ANO":1,"Amount":450,"TDATE":new Date("2005-03-22")},{"TID":"T4","ANO":2,"Amount":360,"TDATE":new Date("2005-03-22")},{"TID":"T5","ANO":1,"Amount":800,"TDATE":new Date("2005-03-22")}]}
Query
db.CUSTOMER.aggregate([{"$lookup":{"from":"ACCOUNT","let":{"cId":{"$toInt":{"$replaceOne":{input:"$CID",find:"C",replacement:""}},}},"pipeline":[{"$match":{"$expr":{"$eq":["$CID","$$cId"]}},},{"$group":{"_id":"$CID","accNos":{"$addToSet":"$ANO"}},},],"as":"matchedAcc"}},{"$lookup":{"from":"TRANSACTIONS","let":{"accNosVar":{"$arrayElemAt":["$matchedAcc.accNos",0]},},"pipeline":[{"$match":{"$expr":{"$in":["$ANO","$$accNosVar"],},},},{"$group":{"_id":"$TDATE","count":{"$sum":1},},},{"$match":{"count":{"$gte":3}},},],"as":"matchedTransactions"},},{"$match":{"matchedTransactions":{"$ne":[]}},},])