i tried to convert into mongodb aggregation famework and every thing runs as expected
[
{
$match: {
$and: [
{ $or: [{ make: null }, { make: "BMW" }] },
{ $or: [{ model: null }, { model: "320" }] },
{ $or: [{ price: null }, { price: { $gte: 1000 } }] },
{ $or: [{ price: null }, { price: { $lte: 80000 } }] },
],
},
},
{ $project: { _id: 0, make: 1, model: 1, price: 1 } },
];
but when not matching a “make” it returns nothing
[
{
$match: {
$and: [
{ $or: [{ make: null }, { make: "asds" }] },
{ $or: [{ model: null }, { model: "320" }] },
{ $or: [{ price: null }, { price: { $gte: 1000 } }] },
{ $or: [{ price: null }, { price: { $lte: 80000 } }] },
],
},
},
{ $project: { _id: 0, make: 1, model: 1, price: 1 } },
];
i want to filtter cars by make, model, price
and when not match make, go to search for rest of query model, price
what should i do, or any other idea to make this filter