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

207
Vistas
How to Make full dynamic search in mongoDB?

I want to make full dynamic search, when user used to type one or two string characters of book in book store UI at search box it should bring all match value from my book table that can be entire my table. The kind of object that user want to search is not important it should bring all matched values.

 const searchObjects = req.query;
 const result =await modelbook.find({
   //this place is for query that i don't know how I should write
 });
 res.status(200).json({resultis: result});
})

and book model has these properties name price Url author ...

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You should use $regex.

const search = asyncWrapper(async (req, res) => {
   var { value } = req.query;

   const result = await modelbook.find({
     $or: [
       { name: { $regex: value, $options: "i" } },
       { price: { $eq: Number(value) ? +value : 0 } },
       { url: { $regex: value, $options: "i" } },
       { description: { $regex: value, $options: "i" } },
       { author: { $regex: value, $options: "i" } }
     ],
   });
   res.status(200).json({ resultis: result });
 })
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