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

270
Vistas
Mongo DB regex in $or operator giving Error "regex has to be a string"

I am working with mongo DB creating a RESTful API. In the get request I want to filter documents from two fields, ether from "name" or "category". For that I am using the $or and $regex operator together. The $regex operator work fine when using without the $or operator. But when the $or operator added it gives this error. MongoServerError: $regex has to be a string. Please help me. Here is my app.js code

app.route("/product")
        .get(function(req, res){
           var queryStr = req.query;
           

            Product.find( { $or: [
                 { name:{ $regex: queryStr.keyword, $options: 'i'}}, 
                 {category: {$regex: queryStr.category, $options: 'i'} } 
                ]}, function(err, docs){
                if(!err){
                    res.send({
                        success: true,
                        count: docs.length,
                        docs
                    })
                } else {
                    res.send(err.stack)
                }    
            })

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