Open KingKnecht opened 2 years ago
I am facing the same issue @KingKnecht did you find the solution to this?
@tuminzee Sorry, for late response. To be honest I don't remember if I got it running or not. But when I check my code I find the following in my controller.js
const getPlannedDishs = catchAsync(async (req, res) => {
const filterParams = pick(req.query, ['from', 'to']);
const dateRangeFilter = {
"$gte" : filterParams.from,
"$lte" : filterParams.to,
}
const mongooseFilter = {
servedAt: dateRangeFilter
}
//const o = {servedAt: {"$gt":"2022-10-10T00:00:00Z"}}
const options = pick(req.query, ['sortBy', 'limit', 'page', 'populate']);
const result = await plannedDishService.queryPlannedDishs(mongooseFilter, options);
res.send(result);
});
and in my service.js
const queryPlannedDishs = async (filter, options) => {
const plannedDishes = await PlannedDish.paginate(filter, options);
console.log(JSON.stringify(plannedDishes));
return plannedDishes;
};
So, for me it looks like I have provided extra parameters on the front-end, extracted my filter params and build a new one on the backend side.
Thank you for your response I will try it out @KingKnecht
I'm trying to filter a date with $gt. This is what I give my axios method on client side for an exact date (which works):
But if I try to put more logic in it, it fails:
server side looks like:
Error message is:
How could I achieve the filtering? Thx