Reputation: 57
I want to filter values from the collections with range of 2 dates:
const filterPattern = {
createdAt: {
'>e': 2020-10-09T14:18:07.240Z,
'<e': 2020-12-09T14:26:49.544Z
}
};
CollectionName.find(filterPattern);
But get an error:
CastError: Cast to date failed for value "{ '>e': 2020-10-09T, '<e': 2020-12-09T14:26:49.544Z }" at path "createdAt" for...
Both of the values '>e' and '<e' I've created by new Date() and they return true after instanceof Date.
What wrong there?
Upvotes: 1
Views: 615
Reputation: 24565
You have to use $
instead of &
and set the values accordingly:
const filterPattern = {
createdAt: {
$gte: "2020-10-09T14:18:07.240Z",
$lte: "2020-12-09T14:26:49.544Z"
}
};
Upvotes: 1