const queryMatch = {departureDate: {$gte: new Date(query.departureDateMin),$lte: new Date(query.departureDateMax)}};
const flightsByCriteria = await this.flightModel.find(queryMatch).exec();
The above request returns an empty table.
And yet I get data with mongodbCompass using ISODate(dateString)
instead of new Date(dateString)
I don’t know where the problem lies in my request ?
Thank for your help.
2
Answers
You should send the dates from the client side in ISO format, so the server would not covert them to the server local time.
When you are sending dates from the client, you can just send them with calling
.toISOString()
method:Then, you can query database like this: