Im creating a search endpoint that will filter the results via a date range.
http://0.0.0.0:3000/api/v1/transactions/search?endDate=2018-10-03T14:07:03.382Z
So the above, wants to search all transactions up to and equal the created_at date.
console.log(req.query.endDate) // 2018-10-03T14:07:03.382Z
This is part of the query i build
created_at = {
gte: startDate,
lte: endDate,
};
let query = {
...query,
created_at
}
const transactions = await Transaction.find(query);
This is what my query string looks like
{ created_at: { lte: '2018-10-03T14:07:03.382Z' } }
However i get the following error.
Cast to date failed for value "{ lte: '2018-10-03T14:07:03.382Z' }" at path "created_at" for model "Transaction""