CastError: Cast to Date/Number/Boolean failed MongoDB Origin: Data OSI layer 7 · Application Last updated 5 Nov 2026

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).

Exact message you may see 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
Seen on: MongoDB Node.js

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

  1. Validate and parse inputs (e.g. zod/joi) before the query
  2. Send ISO 8601 dates
  3. Return HTTP 400 on CastError

Detailed fix by platform

Node.js

  1. if (isNaN(Date.parse(input))) return res.status(400).json({ error: "invalid date" });

How to diagnose

  1. Path — Which field?
  2. Value — What was sent?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

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 (MongoDB)BSONError: input must…CastError ObjectId — CastError: Cast to ObjectId failed for value "x" (type string) at path "_id" (Node.js)CastError ObjectIdDocument failed validation — MongoDB: MongoServerError: Document failed validation (code 121) (MongoDB)Document failed valid…error converting YAML to JSON — error converting YAML to JSON: yaml: line 12: did not find expected key (Kubernetes)error converting YAML…MissingSchemaError: Schema hasn't been registered for model — Mongoose: MissingSchemaError: Schema hasn't been registered for model "User". Use mongoose.model(name, schema) (MongoDB)MissingSchemaError: S…Mongoose ValidationError — ValidationError: User validation failed: email: Path `email` is required. (Node.js)Mongoose ValidationEr…Mongoose: Model.find() no longer accepts a callback — MongooseError: Model.find() no longer accepts a callback (MongoDB)Mongoose: Model.find(…Mongoose: strictQuery will be switched back to false — Mongoose: [MONGOOSE] DeprecationWarning: Mongoose: the strictQuery option will be switched back to false by default in Mongoose 7 (MongoDB)Mongoose: strictQuery…CastError…

Explore the map of this error Full error map →

🧠 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.