Possibly unhandled CastError: Cast to date failed for value "function now() { [native code] } on Mongoose Possibly unhandled CastError: Cast to date failed for value "function now() { [native code] } on Mongoose express express

Possibly unhandled CastError: Cast to date failed for value "function now() { [native code] } on Mongoose


Old question but as mentioned by Ken, to create or update provide the Schema/Model with the Date value

sendHelpDate: Date.now()

This will save to the DB as "sendHelpDate" : ISODate("2018-06-27T10:49:29.328+0000"),as opposed to passing the function of Date.now see below:

    message: 'Cast to Date failed for value "[Function: now]" at     path "sendHelpDate"',    name: 'CastError',            stringValue: '"[Function: now]"',    kind: 'Date',    value: [Function: now],    path: 'sendHelpDate',    reason: [Object]                                                             _message: 'Bookings validation failed',     name: 'ValidationError' }

Hope the extra detail will help someone in future