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

69
Views
updateMany mongoose with multiple condition

I have two documents as in db bookingDetails" as:

{
    "_id":ObjectId("12jj21jan21jdo3kan2idm11"),
    "book_status":"BOOKED",
    "reservation":false,
}

{
    "_id":ObjectId("12jj21jan21jdo3kan2idm11"),
    "book_status":"ACCEPTED",
    "reservation":true,
}

update both of the document with multiple queries.

I am trying as,

bookingDetails.updateMany(
    {
        "book_status":"ACCEPTED",
    },
    {
         $set:{
             "book_status":"DONE"
         }
    }
)

bookingDetails.updateMany(
    {
        "book_status":"BOOKED",
    },
    {
         $set:{
             "book_status":"DONE"
         }
    }
)

But this method is repetitive which increases load on db. Is there any way that it can be optimized?

Please let me know if anyone needs any further information.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use an $or like this:

bookingDetails.updateMany({
  "$or": [
    {
      "book_status": "ACCEPTED"
    },
    {
      "book_status": "BOOKED"
    }
  ]
},
{
  "$set": {
    "book_status": "DONE"
  }
})

Example here

about 4 years ago · Juan Pablo Isaza Report
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!