{
"_id" : ObjectId("61bc628385fcf3659d2291ac"),
"hotel" : ObjectId("61bc621585fcf3659d2291ab"),
"rooms" : [
{
"roomno" : "P1",
}
]
{
"_id" : ObjectId("61bc63f485fcf3659d2291b0"),
"payment" : "COD",
"roomno" : "P1",
"category" : "premium",
"user" : ObjectId("61bc638b85fcf3659d2291af"),
"hotel" : ObjectId("61bc617285fcf3659d2291a9"),
new Promise(async(resolve,reject)=>{
let booking= await db.get().collection(collections.BOOKING_COLLECTION).aggregate([
{
$match:{hotel:ObjectId(hotelID)}
},
{
$lookup:{
from:collections.ROOM_COLLECTION,
localField:'roomno',
foreignField:'rooms.roomno',
as:'bookingrooms'
}
},
{
$lookup:{
from:collections.USER_COLLECTION,
localField:'user',
foreignField:'_id',
as:'user'
}
},
{
$unwind:'$bookingrooms'
}
]).toArray()
console.log("yes booking");
console.log(booking.bookingrooms);
resolve(booking)e here
I want to check the 'roomno' in rooms array in the first collection and 'roomno' in the second collection are the same and I want to get the document if both the rooms match.i use lookup but don't get an answer