# Mongoose: CastError: Cast to date failed for value "abc" (type string) at path "createdAt"

**Code:** `CastError: Cast to Date/Number/Boolean failed` · **Category:** MongoDB · **Seen on:** MongoDB, Node.js

A value couldn't be converted to the schema type at that path (date, number, boolean).

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/mongoose-casterror-cast-to-date-failed)
