MongoDB: MongoServerError: Document failed validation (code 121)
The collection has a JSON Schema validator and the inserted/updated document doesn’t satisfy it.
Seen on:
MongoDB
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
- Read errInfo.details for the failing property
- Convert types before insert (new Date(), Number())
- Update the validator or app schema
Detailed fix by platform
Shell
mongosh "$MONGODB_URI" --eval 'db.getCollectionInfos({name:"orders"})[0].options.validator'
How to diagnose
- Details — errInfo.details.schemaRulesNotSatisfied
- Types — Document field types
🔧 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
Most viewed in MongoDB
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026