Database
db={"resort":[{_id:1,name:"Hilton"}],"room":[{_id:1,resort_id:1,room_status:"Available",/** Ongoing, Available*/no_of_persons_allowed:7},{_id:2,resort_id:1,room_status:"Available",/** Ongoing, Available*/no_of_persons_allowed:6}],"booking":[{_id:1,booking_room_id:1,booking_resort_id:1,booking_status:"Booked",/** Booked, Ongoing, Completed*/checkIn_date:ISODate("2022-10-01T00:00:00.000Z"),checkOut_date:ISODate("2022-10-03T00:00:00.000Z")},{_id:2,booking_room_id:1,booking_resort_id:1,booking_status:"Booked",/** Booked, Ongoing, Completed*/checkIn_date:ISODate("2022-10-13T00:00:00.000Z"),checkOut_date:ISODate("2022-10-15T00:00:00.000Z")}]}
Query
db.room.aggregate([{$match:{no_of_persons_allowed:{$gte:6},room_status:"Available"}},{$lookup:{from:"booking",localField:"_id",/** if room_id is unique even in different resort*/foreignField:"booking_room_id",as:"isbooking",pipeline:[{$match:{$expr:{$and:[{$gt:["$checkOut_date",ISODate("2022-10-02T00:00:00.000Z")/** customer checkin day*/]},{$lt:["$checkIn_date",{$dateAdd:{startDate:ISODate("2022-10-02T00:00:00.000Z"),/** customer checkin day*/unit:"day",amount:7}}]},{$ne:["booking_status","Completed"]}]}}}]}},{$match:{isbooking:[]}},{$lookup:{from:"resort",localField:"resort_id",/** if room_id is unique even in different resort*/foreignField:"_id",as:"resorts"}}])