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

134
Views
Búsqueda de mangosta Por condición, de lo contrario, encuentre todo ($ o)

si pasas categoryId devolverá categoría con ese categoryId pero si no lo pasas, quiero que esta ruta devuelva todas las categorías ... Intenté esto con $or pero siempre devuelve todas las categorías independientemente de si pasé categoryId o no :

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

Puedo usar la declaración if pero requiere mucho código, ¿se puede hacer esto de manera más limpia?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Algo como esto:

 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!