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

240
Vistas
Mongodb - How can I combine two "query.$or" statements with "query.$and"?

I want to filter the documents that satisfy

(title = searchWord OR content = searchWord) AND (category = category OR category = category).

And I want to combine two OR statements, which are option 1 and 2 below, and I tried to do, but it doesn't work! Please help me to rectify it.

I want to keep the form of option 1 and option 2, and combine the two OR statements with AND .

    //option 1
    query.$or = [{ title: searchWord }, { content: searchWord }]; 

    //option 2
    query.$or = [{ category: category }, { category: category }];


    //It doesn't work!!
    query.$and = [{$or : [{ title: searchWord }, { content: searchWord }]},
                  {$or : [{ category: category }, { category: category }]}];
    
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is the mongodb query which can be of use to you. It uses an implicit and. Make sure to replace your collectionName.

db.collectionName.find({
    $or : [ 
        {"title": searchWord},
        {"content": searchWord}
    ],
    "category": category         
})
about 4 years ago · Juan Pablo Isaza 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