# MongoDB: MongoServerError: Document failed validation (code 121)

**Code:** `Document failed validation` · **Category:** MongoDB · **Seen on:** MongoDB

The collection has a JSON Schema validator and the inserted/updated document doesn’t satisfy it.

## Meaning

MongoDB 5+ includes errInfo details listing the failing rules (missing required fields, wrong bsonType, pattern mismatch). Mongoose validation (ValidationError) is separate and runs before the server.

## Common causes

- Required field missing
- Wrong BSON type (string vs int/date)
- Value not matching enum/pattern
- Validator changed but app not updated

## Quick fix

1. Read errInfo.details for the failing property
2. Convert types before insert (new Date(), Number())
3. Update the validator or app schema

## Detailed fix by platform

### Shell

1. `mongosh "$MONGODB_URI" --eval 'db.getCollectionInfos({name:"orders"})[0].options.validator'`

## How to diagnose

1. **Details** — errInfo.details.schemaRulesNotSatisfied
2. **Types** — Document field types

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/document-failed-validation)
