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

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

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 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!