I am getting stuck on my MERN application. I want the user to filter the results of the product. The more criteria the user applies, the narrower the results should be. Eg, if I apply the filter boy, there are 10 results. Then I am trying to apply pants, there should be the only 5 results which matches what I am looking for. But now it doesn't work. Here is the code,
exports.getProductsSearchResult = (req, res, next) => {
let query = {};
const productCategory = req.query.category;
const productSize = req.query.size;
const productGender = req.query.gender
if (productCategory !== undefined) query.category = productCategory;
if (productGender !== undefined) query.gender = productGender;
if (productSize !== undefined) query.size = productSize;
console.log('query', query)
Products.find(query).then(product => {
// console.log(product)
res.status(200).json(product)
}).catch(err => {
console.log(err)
})
}
console.log('query', query)
? Also explain what is "it doesn't work". Where/what is the problem? – J.F. Nov 25 '20 at 21:13