A real collection
Create a recipes collection with nested ingredients, then answer questions and make changes with the operators from this unit.
Shape the recipe document
This project is small on purpose. Practising the full cycle of inserting, querying, projecting, updating and deleting on one collection builds the habits you'll rely on in larger apps, where the same operators appear in every feature.
A recipe is read as a whole — title, time, tags and ingredients all appear on the same screen — so it's one document. Ingredients are an array of small objects, each with an item and a quantity, because they belong to the recipe and the list is short. Tags are a plain array of strings, which MongoDB matches element by element.
db.recipes.insertOne({
title: "Momo",
minutes: 60,
difficulty: "medium",
tags: ["nepali", "steamed"],
ingredients: [
{ item: "flour", qty: 2, unit: "cups" },
{ item: "cabbage", qty: 1, unit: "head" },
],
});