Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!