Mongoose: CastError: Cast to date failed for value "abc" (type string) at path "createdAt"
A value couldn't be converted to the schema type at that path (date, number, boolean).
CastError: Cast to date failed for value "abc" (type string) at path "createdAt"CastError: Cast to Number failed for value "abc" at pathCast to Boolean failed for valueCast to string failed for valueCastError: Cast to Array failed for value Meaning
Input validation: parse and validate values before querying/saving (new Date(value), Number()), use ISO strings for dates, and catch invalid input in the API layer returning 400. The message gives the path and the offending value.
Common causes
- Invalid date string from the client
- Non-numeric string for a Number field
- "true"/"false" strings vs Boolean
- Empty string for a typed field
- Wrong field type in schema
⚡ Quick fix
- Validate and parse inputs (e.g. zod/joi) before the query
- Send ISO 8601 dates
- Return HTTP 400 on CastError
Detailed fix by platform
Node.js
if (isNaN(Date.parse(input))) return res.status(400).json({ error: "invalid date" });
How to diagnose
- Path — Which field?
- Value — What was sent?
- Validation — Before DB?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- BSONError: input must be a 24 character hex string BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters
- CastError ObjectId CastError: Cast to ObjectId failed for value "x" (type string) at path "_id"
- Document failed validation MongoDB: MongoServerError: Document failed validation (code 121)
Most viewed in MongoDB
- MongoParseError MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
- bad auth : Authentication failed MongoDB: MongoServerError: bad auth : Authentication failed (code 8000 / 18)
- AlreadyInitialized: already initialized MongoServerError: already initialized (rs.initiate on a configured replica set)
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026