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

87
Vistas
How Do I Make a Multi-filter Search?

I'm building an ecommerce site with Vanilla JS, Node and MongoDB. My search bar currently can only return searches based upon the name of the product as follows:

productRouter.get('/', expressAsyncHandler(async (req, res) => {
    const searchKeyword = req.query.searchKeyword
    ? {
        name: {
            $regex: req.query.searchKeyword,
            $options: 'i'
            }
        }
    : {};
    const products = await Product.find({...searchKeyword});
    res.send(products);
    })
);

I've tried adding category and brand inside of the ? {} like so to no avail:

? {
        name: {
            $regex: req.query.searchKeyword,
            $options: 'i'
            }, 
        category: {
            $regex: req.query.searchKeyword,
            $options: 'i'
            }, 
        brand: {
            $regex: req.query.searchKeyword,
            $options: 'i'
            }
  }

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could use the search text feature.

It would be something like this:

// Creating compound index on db
db.product.createIndex({ name: 'text', category: 'text', brand: 'text' })

// Executing query
db.product.find({ $text: { $search: "something" } })

If you're using Mongoose, here is demonstrating how to create an index.

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