I have created an API using Node.js/Express that receives input from a form including a date option in the request body.
Currently, I am sending dates in the format YYYY-mm-dd
, and I have also attempted using dd/mm/YYYY
. However, when testing in Postman, the server crashes with the following error:
UnhandledPromiseRejectionWarning: ValidationError: profile validation failed: experience.0.from: Cast to Date failed for value "2017-14-09" at path
"from"
at new ValidationError (D:\ReactDev\MERN Dev\DevConnect\dev-connect\node_modules\mongoose\lib\error\validation.js:30:11)
at model.Document.invalidate (D:\ReactDev\MERN Dev\DevConnect\dev-connect\node_modules\mongoose\lib\document.js:1957:32)
at EmbeddedDocument.invalidate (D:\ReactDev\MERN Dev\DevConnect\dev-connect\node_modules\mongoose\lib\types\embedded.js:287:19)
The user should be able to input dates in any desired format. How can I receive this input without encountering errors? Is there a correct approach to handling this issue? Thank you.