javascript - Mongoose: Cast to date failed for value when updating a document -
I use Mongoos in my project and I use date fields in one of the schemas like: < / P>
Reservation Date: {Type: Date, Default: Date. Now} I can make a document with this field without this problem and when I made it, I am consoling this date: < Code> Reservation Date: Thursday 20 November 2014 04:45:00 GMT + 0100 (CET)
However, there is a problem even when I try to update this document (Without changing the reservation date field). Here is an error message:
Name: 'Cast error', message: 'To fail to price, cast to date' 20/11/2014 04:11 "On the path Casterror: "Reservations" on the path "Cost of the date" 20/11/2014 04:11 "Reservations" "
I hereby submit this document to the server (Revision, Req.body); reservation.save (function (error, update security) {if (err) {/ / Handle} return res.json (reservation);});});
and date req.body
Any ideas which may be the reason for this error?
Thanks!
" 20/11/2014 04:11 "
is an invalid ISODate format. You are changing the reservation date in a passive format string. You need to convert it to valid ISODate format (month first day):
New date ("11/20/2014 04:11") // Thursday 20 November 2014 04:11 : GMT + 0100 (CET) New Date ("2014/11/20 04:11") // Thursday 20 November 2014 04:11:00 GMT + 0 100 (CET) New Date ("20/11/2014 04:11") For the easy manipulation of date formats // invalid date
, I
Great Post with valuable information. I am glad that I have visited this site. Share more updates.
ReplyDeleteBest IELTS Coaching in Chennai
IELTS Coaching center in Chennai