Database

db={"swaps":[{"_id":1,userId:5,matchStatus:0,organisationId:1,location:"Tongham",type:"SRV",from:ISODate("2023-03-01T06:00:00Z"),to:ISODate("2023-03-01T18:00:00Z"),offers:[{from:ISODate("2023-03-02T05:00:00Z"),to:ISODate("2023-03-02T19:00:00Z"),locations:["Chertsey","Brighton","Guildford"],types:["DCA"],},{from:ISODate("2023-03-03T05:00:00Z"),to:ISODate("2023-03-03T19:00:00Z"),locations:["Tongham","Brighton"],types:["SRV"]}]},{"_id":2,userId:2,matchStatus:0,organisationId:1,location:"Chertsey",type:"DCA",from:ISODate("2023-03-02T06:00:00Z"),to:ISODate("2023-03-02T18:00:00Z"),offers:[{from:ISODate("2023-03-01T05:00:00Z"),to:ISODate("2023-03-01T19:00:00Z"),locations:["Brighton","Tongham"],types:["SRV","DCA"],}]},{"_id":3,userId:3,matchStatus:0,organisationId:1,location:"Brighton",type:"SRV",from:ISODate("2023-03-03T06:00:00Z"),to:ISODate("2023-03-03T18:00:00Z"),offers:[{from:ISODate("2023-03-01T05:00:00Z"),to:ISODate("2023-03-01T19:00:00Z"),locations:["Brighton","Tongham","Chertsey"],types:["DCA","SRV"],}]}],"users":[{"_id":1,"name":"John",},{"_id":2,"name":"Julie",},{"_id":3,"name":"Ryan",},]}

Query

db.swaps.aggregate([{$match:{}},{$unwind:"$offers"},{$lookup:{from:"swaps",as:"matches",let:{parentId:"$_id",parentOrganisationId:"$organisationId",parentUserId:"$userId",parentLocations:"$offers.locations",parentTypes:"$offers.types",parentOffersFrom:"$offers.from",parentFrom:"$from",parentTo:"$to",parentOffersTo:"$offers.to",parentLocation:"$location",parentType:"$type"},pipeline:[{$match:{matchStatus:0,matchId:null,$expr:{$and:[{"$ne":["$_id","$$parentId"]},{$ne:["$userId","$$parentUserId"]},{"$eq":["$organisationId","$$parentOrganisationId"]},{$in:["$location","$$parentLocations"]},{$in:["$type","$$parentTypes"]},{$lte:["$$parentOffersFrom","$from"]},{$gte:["$$parentOffersTo","$to"]},{"$anyElementTrue":{"$map":{"input":"$offers","as":"offer","in":{"$and":[{$in:["$$parentLocation","$$offer.locations"]},{$in:["$$parentType","$$offer.types"]},{$lte:["$$offer.from","$$parentFrom"]},{$gte:["$$offer.to","$$parentTo"]},]}}}}]}}},{"$lookup":{"from":"users","localField":"userId","foreignField":"_id","as":"matchedUser"}},{"$set":{"matchedUser":{"$ifNull":[{$first:"$matchedUser"},null]}}}]}},{"$group":{"_id":"$_id","doc":{"$first":"$$ROOT"},"matches":{"$push":"$matches"},"offers":{"$push":"$offers"}}},{"$set":{"matches":{"$reduce":{"input":"$matches","initialValue":[],"in":{"$concatArrays":["$$value","$$this"]}}}}},{"$replaceRoot":{"newRoot":{"$mergeObjects":["$doc",{matches:"$matches",offers:"$offers"}]}}},{"$lookup":{"from":"users","localField":"userId","foreignField":"_id","as":"user"}},{"$set":{user:{"$ifNull":[{"$first":"$user"},null]}}},{"$sort":{_id:1}}])

Result