Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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 Respuestas
Responde la pregunta

0

Something like this:

await Category.find({ _id: (categoryId || {$exists: true}) });
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda