Transactions and the Relational Choice
Keep a checkout from selling a bike that's already gone: see why a single-document update is already safe, and when a transaction is needed. Then, if you know SQL, see the same store designed both ways, and learn when a relational database is the better choice.
Updated
Transactions
- Transactions, and Why You'll Need Them Less (Journeyman): When two shoppers reach for the last bike, a conditional updateOne keeps the stock right on its own, and when the stock and a new order must change together, a transaction makes both changes happen or neither.
If You Know SQL
- If You Know SQL: One Store Designed Both Ways (Journeyman): Riverbend Bike Shop's store as SQL tables beside the same store as MongoDB documents, the words that carry over from one to the other, and the relational habits that don't.
- If You Know SQL: Queries Side by Side (Apprentice): The SQL you already write beside its MongoDB twin, from SELECT with WHERE, ORDER BY and a row limit to INSERT, UPDATE and DELETE, with a first look at GROUP BY and JOIN in a pipeline.
Choosing Relational
- When a Relational Database Is the Better Choice (Journeyman): An honest look at the apps where a relational database fits better than documents, such as money moving between many records, reports that join data in ways nobody planned, and a shape many teams must share, and why many apps use both.
Exercise: Checkout Without Overselling
- Exercise: Checkout Without Overselling (Journeyman): Write the five statements behind Riverbend Bike Shop's checkout and cancel, from a stock update that never sells a bike twice to a restock, and let the tests run two checkouts at once and a cancel inside a transaction.
Up Next: Aggregation and Indexes
- Up Next: Aggregation and Indexes (Journeyman): Look back at what Module 3 lets you design, see it applied to a whole store's screens, and see what Module 4 adds, reports built from a year of orders and indexes that keep them fast.