MongoDB data modelling
Starting from the application’s access patterns, you decide between embedding and referencing and design flexible yet orderly collections with schema validation and versioning.
Level 201 · 18 lessons · 15 practice labs
Lessons
Thinking in documents
- Documents versus rows: thinking differently
- Designing from access patterns
- Embed or reference
- Three shapes of one-to-many
- Many-to-many relationships
- Short task: a model for a blogging platform
Patterns
- The attribute pattern
- The extended reference
- The subset pattern
- The computed pattern
- The bucket pattern and time series collections
- Tree structures
- Short task: a model for sensor data
Order
- Schema validation in depth
- Schema versioning and migration
- Document size limits and growing arrays
- Anti-patterns to avoid
- Capstone: an online shop catalogue and order model
Practice labs
- List the access patterns: From the screens of a booking app, list which queries will run and how often.
- Decide between embedding and referencing: Decide which relationships in a school's student, parent and course data to embed or reference, justify it and build it.
- Move a relational schema to a document model: Turn a six-table order schema into a document model based on access patterns and answer the top two queries in one read each.
- Embed reviews in a product: In a catalogue with few reviews per product, embed reviews in the product document and show them with one query.
- Model a many-to-many relationship: Model the many-to-many link between courses and students so both directions query quickly.
- Split an endlessly growing comment array: Move a comment array that strains document size on popular posts into its own collection and set up paged reads.
- Store varying product attributes with the attribute pattern: Move different categories' properties into a key-value array and make them searchable with a single index.
- Pre-compute a frequently read total: Keep a view count and rating average that is recalculated on every page load in the document with the computed pattern.
- Build an extended reference for orders: Copy a customer's stable fields into orders, add the last 10 orders to the customer with the subset pattern and write the update rule.
- Put sensor readings into a time series collection: Create a time series collection for greenhouse humidity sensors and compute hourly averages.
- Design hourly bucket documents: Build the bucket pattern that groups minute-by-minute temperature readings into one document per device per hour and compare document counts.
- Model a category tree for up and down queries: Model a shop's category tree with an ancestors array and parent reference, then query a branch's subcategories and path.
- Add a schema version field: Add a schemaVersion field to profile documents and count how many documents are on each version.
- Write code that reads old and new shapes: Write a read layer that shows user documents correctly whether the name field is split in two or not.
- Find and fix the anti-patterns in a schema: Find huge arrays, needless collections and oversized documents in an inherited database and apply a fix plan.
About this course
Starting from the application’s access patterns, you decide between embedding and referencing and design flexible yet orderly collections with schema validation and versioning.
What you will learn
- Thinking in documents
- Patterns
- Order
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.