I am trying to search products by price range with MongoDB aggregate.But I didn’t solve this yet.Help me, anyone,please
[
{
"$search": {
"compound": {
"should": [
{
"text": {
"path": ["category", "price", "title", "shop"], "query": `\"${search}\"`,
"score": {
"constant": {
"value": 1
}
}
}
}
],
"must": [
{
"text": {
"path": ["title", "category", "shop", "price"],
"query": `\"${search}\"`,
}
}
,{
"text": {
"query": `{price:{$gte:${Number(lowestPrice)},$lte:${Number(highestPrice)}}}`,
"path": 'price',
"score": {
"constant": {
"value": 1
}
}
}
}
],
}
}
},
{$project: {
"_id": 1,
"title": -1,
"category": 1,
"price": { $cond: [{ $eq: ["$price", null] }, "$$REMOVE", "$price"] },
"price": { $cond: [{ $eq: ["$price", 0] }, "$$REMOVE", "$price"] },
"shop": 1,
"createdAt": 1,
"link": 1,
"image": 1,
"score": { "$meta": "searchScore" },
"highlight": { "$meta": "searchHighlights" }
}}
];
price filtering doesn’t working
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.