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

143
Views
Mongoose find By condition otherwise find all ($or)

if you pass categoryId it will return category with that categoryId but if you don't pass it, I want this route to return all categories... I tried this with $or but it always returns all categories regardless of I passed categoryId or not :

await Category.find({ $or: [{ _id: categoryId }, {}] });

I can use the if statement but it takes a lot of code, can this be done cleaner?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Something like this:

await Category.find({ _id: (categoryId || {$exists: true}) });
over 4 years ago · Santiago Trujillo 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!