Koskamo

Schema validation

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

MongoDB uses a flexible schema model: by default, documents in a collection do not need the same fields or data types. After you establish an application schema, use schema validation to create rules for fields — allowed data types and value ranges — to prevent unintended schema changes and data type errors. Validation is most useful for an established application with a defined data structure, and rules are flexible: they need not cover every field unless your application requires it. Typical rules ensure an events collection's start_date stores only a date rather than a string, restrict accepted_credit_cards to values such as Visa, MasterCard, and American Express, or require gpa to be a positive floating-point number. Once rules are added, all document inserts must match them, and the validation level determines how rules apply to existing documents and updates. By default, MongoDB rejects any insert or update that would produce an invalid document; alternatively, you can configure it to allow invalid documents and log a warning. For Atlas deployments, validation can be implemented in the UI. Scope: MongoDB. Reviewed October 4, 2026.

Source and provenance

Original source
www.mongodb.com
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.