Skip to main content

Document Design and Modeling

Schema Design Principles

0:00
LearnStep 1/2

Schema Design

MongoDB Schema Design

Schema-Less vs Schema-Full

MongoDB is schema-flexible, but you should still design consistent schemas:

python

Design for Your Queries

Unlike SQL, MongoDB schema should be designed around how you query data.

python

Schema Design Guidelines

ConsiderationEmbedReference
Data relationshipContains (1:1, 1:few)References (1:many, many:many)
Access patternAlways accessed togetherAccessed separately
Data sizeEmbedded data is smallData can grow large
Update frequencyRarely updatedFrequently updated
Atomicity needNeed atomic updatesCan use transactions

Document Size Limits

python

Field Naming Conventions

python
Schema Design Principles | MongoDB with Python Mastery | Mathematicon