Validation for MongoDBs
MongoDB validation is enforcing structure on a flexible database. Collection-level JSON Schema validators reject documents that break rules such as required fields or types, and ODMs such as Mongoose add schemas and checks in application code. This unit is in the Data Modelling stage and balances flexibility with data quality.
Stage: Data Modelling · Part of the MongoDB roadmap · Last reviewed 19 November 2026
What to learn in Validation
- Create a collection with a $jsonSchema validator for required fields and types
- Choose validationLevel and validationAction for existing and new documents
- Define a Mongoose schema with types, defaults and required flags
- Add custom validators and unique indexes to catch bad data
- Explain what the database enforces versus what the ODM enforces
Validation interview questions
Is MongoDB really schemaless?
Not entirely. Collections do not force a fixed structure by default, but the application still assumes one. You can enforce rules with JSON Schema validation on the collection, and many teams add ODM schemas. The schema is flexible, not absent.
Why is Mongoose validation not enough on its own?
Mongoose validates only data that passes through it. Other applications, scripts or shell users can write to the same collection and bypass those rules. Database-level validators and unique indexes protect the data no matter which client writes it.
Where Validation fits in the MongoDB roadmap
Validation belongs to the Data Modelling stage (intermediate level), which takes about 12 hours. Design for access patterns.
Other units in this stage
Back to the full MongoDB roadmap