I just realised that mongoose-paginate IS NOT supporting Comparison Query Operators https://docs.mongodb.com/manual/reference/operator/query-comparison/
Example:
(created_on: Date
)
Post.paginate({
created_on: {
gte: new Date('2019-01-01T00:00:00.000Z')
}
}, {
page: 2,
limit: 10,
sort: {
created_on: 'desc'
}
}).then((data) => {
// do something with docs
});
This will throw an error:
CastError: Cast to date failed for value "{ gte: 2019-01-01T00:00:00.000Z }" at path "created_on" for model "Post"
It seems like it compares the property created_on
with the whole object {$gte: new Date('2019-01-01T00:00:00.000Z')}
and it ignores that operator $gte
.
In the example above, it tries to compare a date with an object which ends up thrown a cast error!
Actually it was my mistake, forgot to put $ sign before gte
My bad, it was my mistake that I forgot $ before gte
Post.paginate({
created_on: {
$gte: new Date('2019-01-01T00:00:00.000Z')
}
}, {
page: 2,
limit: 10,
sort: {
created_on: 'desc'
}
}).then((data) => {
// do something with docs
});