-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Open
Labels
new featureThis change adds new functionality, like a new method or classThis change adds new functionality, like a new method or class
Milestone
Description
Do you want to request a feature or report a bug?
What is the current behavior?
I have a birthday field that the client send a string like "03/02/2000" and I convert it via set to a Date
Is it possible to define two types the first one String (the first validation by mongoose to check if it's a string) and a second type of Date (when I read it from the DB)
birthday: {
type: SchemaTypes.Date
set: (value: string) => {
return value ? startOfDay(parse(value, 'DD/MM/YYYY', new Date())).toISOString() : null;
}
}
What is the expected behavior?
Right now I get the following error
mongoose validation error Cast to Date failed for value "03/02/2000" (type string) at path "birthday"
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Currently I use the "latest version" 6.0.11
gituser3000, callumgare, chan71, HHogg, Goolyio and 2 more
Metadata
Metadata
Assignees
Labels
new featureThis change adds new functionality, like a new method or classThis change adds new functionality, like a new method or class