Tables and Documents: Two Ways to Store a Recipe
A recipe card with lists of ingredients and steps breaks a single spreadsheet table; a relational database splits it into tables joined back together, and a document database keeps the whole card in one document.
Novice · MongoDB · Database · Updated
After this lesson you can
- Explain where one spreadsheet table breaks for a recipe with lists of ingredients and steps
- Compare storing a recipe as rows in related tables with storing it as one document in a collection
Key takeaways
- One spreadsheet table breaks for a recipe with lists, whether you add a column per ingredient or repeat the recipe on a row per ingredient.
- A relational database splits the card into tables, such as recipes, ingredients and steps, linked by the recipe's id and joined back together to read it.
- A document database keeps the whole card in one document, with its lists inside it.
- A table holds rows and a collection holds documents; a database holds the tables or the collections.
Every app that saves anything decides the shape of its data before the first record goes in. Get the shape wrong, and every screen that reads it pays: copies that disagree, empty boxes to skip, slow pages. You'll make this choice at the start of every project you build, so this lesson takes one real thing, a recipe card, and stores it two ways, to show what each shape is good at.
The example is Sunday Kitchen's Saturday Pancakes card: eight ingredients, five steps, a small nutrition box, a few tags and a rating.
One table, and where it breaks
Most people's first database is a spreadsheet: one table, with a column for each kind of detail and a row for each recipe. The name, the minutes and the servings fit well. Then come the ingredients.
Try 1: a column for each ingredient.
| name | minutes | ingredient1 | ingredient2 | ingredient3 | ingredient4 |
|---|---|---|---|---|---|
| Saturday Pancakes | 25 | 2 cups flour | 2 tablespoons sugar | 2 teaspoons baking powder | 0.5 teaspoon salt |
| Lemon Bars | 50 | 2 cups flour | 1 cup butter | 1.5 cups sugar | 3 lemons |
That goes on to ingredient8 for the pancakes. Lemon Bars needs only four, so its other four cells sit empty. A stew with fourteen ingredients means six new columns, for every recipe. And "which recipes use butter?" means checking every ingredient column, one by one.
Try 2: a row for each ingredient.
| name | minutes | ingredient |
|---|---|---|
| Saturday Pancakes | 25 | 2 cups flour |
| Saturday Pancakes | 25 | 2 tablespoons sugar |
| Saturday Pancakes | 25 | 2 teaspoons baking powder |
And five more rows like them. Now the name and the minutes are copied eight times. Change the minutes to 20, and you must change eight rows; miss one, and the sheet disagrees with itself. The five steps are a second list that needs rows of its own, and the two lists don't line up.
The relational answer: tables joined together
Databases solved this decades ago by splitting the card into pieces. A relational database keeps each kind of thing in its own table: one table for recipes, one for ingredients, one for steps. Each row is one record: one recipe, or one ingredient line. Every ingredient row carries the id of its recipe, 1 for Saturday Pancakes, which links it back.
The recipes table:
| id | name | minutes | servings |
|---|---|---|---|
| 1 | Saturday Pancakes | 25 | 4 |
The ingredients table:
| recipe_id | name | amount | unit |
|---|---|---|---|
| 1 | flour | 2 | cup |
| 1 | sugar | 2 | tablespoon |
| 1 | baking powder | 2 | teaspoon |
The steps table works the same way, one row per step. Nothing is copied: the name lives in one row, and each ingredient once. To show the card, the database joins the tables back together: it finds recipe 1, then every ingredient row and every step row whose recipe_id is 1. This is the shape behind most business software, and SQL (read "sequel" or "S-Q-L") is the language that asks it questions. This course needs no SQL.

The document answer: one record that holds its lists
A document keeps the card in one piece, the way the paper card does, with its lists inside it. Here is the Saturday Pancakes card as one document, the way mongosh shows it. You'll write it yourself in Arrays and Documents Inside Documents; the square brackets around it are mongosh's list of the cards it found, here one.
[
{
name: 'Saturday Pancakes',
minutes: 25,
servings: 4,
ingredients: [
{ name: 'flour', amount: 2, unit: 'cup' },
{ name: 'sugar', amount: 2, unit: 'tablespoon' },
{ name: 'baking powder', amount: 2, unit: 'teaspoon' },
{ name: 'salt', amount: 0.5, unit: 'teaspoon' },
{ name: 'milk', amount: 1.5, unit: 'cup' },
{ name: 'eggs', amount: 2, unit: 'whole' },
{ name: 'butter', amount: 3, unit: 'tablespoon' },
{ name: 'vanilla', amount: 1, unit: 'teaspoon' }
],
steps: [
'Whisk the flour, sugar, baking powder and salt in a big bowl.',
'Whisk the milk, eggs, melted butter and vanilla in another bowl.',
'Stir the wet mix into the dry mix. A few lumps are fine.',
'Heat a greased pan over medium heat.',
'Pour a quarter cup of batter for each pancake, and flip it when bubbles form.'
]
}
]
The ingredients are a list inside the card, and so are the steps. Showing the card means reading one document; nothing needs joining. A collection holds many documents, the way a recipe box holds many cards. MongoDB, the database this course teaches, is a document database.
The words, side by side
| Relational database | MongoDB | What it is |
|---|---|---|
| table | collection | Holds many records of one kind, such as recipes |
| row | document | One record: one recipe card |
| column | field | One detail, such as the minutes |
| a row in another table, joined back | a list inside the document | How a card keeps its ingredients |
| database | database | Holds the tables, or the collections |
Neither shape wins everywhere. Tables keep one copy of everything and can combine data in any way you ask; documents keep what's read together in one place. Where Documents Fit, and Where They Don't weighs the two honestly, and The NoSQL Families in Plain Words shows the other shapes databases come in.
Check yourself
2 questions to try on the lesson page.
So what
Before you store anything, you can see the choice every app makes: split a record into tables joined back together, or keep it whole as one document.