I was creating a full stack e-commerce website, when i came across this problem. I wanted to add a search filtering based on reviews star. The client sends query and minRatings to the server and the API sends a query to the mongodb database searching for product which matches the query and the review stars should be greater or equal to minRating
.
Here’s what i tried but this didn’t worked
The query is written using Mongoose
const products = await Product.find({
$or: [
{ name: { $regex: query, $options: "i" } },
{ productType: { $regex: query, $options: "i" } },
],
stars: { $gte: parseFloat(minRatings), $lte:5 },
}).populate("reviews");
Hope you understood my problem and can help me with finding the solution.