Database

db={"notification":[{"_id":1,"category":"LOUNGE_JOIN_REQUEST","lounge_join_request":1},{"_id":2,"category":"LOUNGE_JOIN_REQUEST","lounge_join_request":2},{"_id":3}],"lounge_join_requests":[{"_id":1,"lounge":1,},{"_id":2,"lounge":1,},{"_id":3,"lounge":2,},],"lounge":[{"_id":1,"name":"L1",},{"_id":2,"name":"L2",},]}

Query

db.notification.aggregate([/** Match notifications with lounge join requests*/{$match:{category:"LOUNGE_JOIN_REQUEST",lounge_join_request:{$ne:null},},},/** Select a random notification using $sample*/{$sample:{size:1}},{$lookup:{from:"lounge_join_requests",localField:"lounge_join_request",foreignField:"_id",as:"lounge_join_request",},},/** Project the lounge ID*/{$project:{_id:0,lounge_id:"$lounge_join_request.lounge"}},])

Result