Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
How to check if a field in a document and a field inside an array in other document are same using lookup in mongodb
    {
"_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

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!