Date Casting error in mongoose with node.js
mongodb, mongoose, node.js
Solution
The CastError is throwed due to the date string 24/01/2014 is not a valid date format for mongoDB. MongoDB uses ISODate as the Date format. The solution for this problem is convert the date 24/01/2014 to 01/24/2014. This can be done easily with a npm module called moment.js.
Problem
Date Casting issue while inserting data to mongoDB using mongoose. Model Looks Like this : ``` var userSchema = new Schema({ emailid: String, createddate: Date, status: String}); ``` The value i am trying to save ``` { emailid: 'test@testwert.com', status: 'Activv', createddate: '24/01/2014' } ``` Error : ``` { message: 'Cast to date failed for value "24/01/2014" at path "createddate"', name: 'CastError',type: 'date',value: "24/01/2014",path: 'createddate' } ``` I tried `new Date(Date.parse(userObject. createddate))`