The Sample Database
Every mongosh run example in this course starts in a brand-new database that already contains a small online store called TAD Coffee. The data is loaded by a seed script (scripts/mongodb/seed.js in the site's repository) that runs silently before your code. Because each example gets its own fresh copy, you can insert, update, delete and even drop collections without affecting any other example.
The store has three collections:
| Collection | Documents | What it holds |
|---|---|---|
products |
20 | coffee, tea, equipment, snacks and merch, with price, stock, tags and a rating |
customers |
12 | name, optional email, loyalty tier, sign-up date, embedded address and interests |
orders |
20 | which customer ordered, when, the status, the embedded line items and the total |
products
print(db.products.findOne({ _id: 11 }));{
_id: 11,
name: 'French Press',
category: 'equipment',
price: 35,
stock: 9,
tags: [ 'brewing' ],
rating: 4.2,
specs: {
material: 'glass',
color: 'black',
weightGrams: 820,
capacityMl: 1000
}
}
| Field | Type | Notes |
|---|---|---|
_id |
integer | 1 to 20 |
name |
string | |
category |
string | coffee (5), tea (4), equipment (6), snacks (4), merch (1) |
price |
number | in dollars, for example 24.5 |
stock |
integer | units in the warehouse; four products are sold out (0) |
tags |
array of strings | for example ['dark', 'whole-bean'] |
rating |
number | average review score, 3.6 to 4.9 |
specs |
embedded document | only on equipment, except the paper filters: material, color, weightGrams, sometimes capacityMl |
Here is the whole catalogue, one line per product:
db.products.find().forEach(p => {
print(p._id, p.name, '|', p.category, '|', p.price, '|', p.stock);
});1 Espresso Beans | coffee | 24.5 | 40
2 House Blend | coffee | 18 | 65
3 Ethiopia Yirgacheffe | coffee | 27 | 12
4 Colombia Supremo | coffee | 21 | 0
5 Decaf Night Owl | coffee | 19.5 | 22
6 Green Sencha | tea | 12 | 30
7 Earl Grey | tea | 9.5 | 80
8 Chamomile Calm | tea | 8 | 0
9 Masala Chai | tea | 11 | 18
10 Pour-Over Dripper | equipment | 29 | 15
11 French Press | equipment | 35 | 9
12 Burr Grinder | equipment | 89 | 6
13 Gooseneck Kettle | equipment | 59 | 4
14 Milk Frother | equipment | 25 | 0
15 Paper Filters (100) | equipment | 6 | 120
16 Almond Biscotti | snacks | 7.5 | 50
17 Dark Chocolate Bar | snacks | 4.5 | 75
18 Oat Cookies | snacks | 5 | 0
19 Salted Pretzels | snacks | 3.5 | 40
20 Travel Mug | merch | 16 | 25
customers
print(db.customers.findOne({ _id: 1 }));
print(db.customers.findOne({ _id: 4 }));{
_id: 1,
name: 'Ada Lovelace',
email: 'ada@example.com',
tier: 'gold',
joined: ISODate('2026-01-04T09:15:00.000Z'),
address: { city: 'London', country: 'UK' },
interests: [ 'coffee', 'equipment' ]
}
{
_id: 4,
name: 'Linus Torvalds',
tier: 'standard',
joined: ISODate('2026-02-02T17:45:00.000Z'),
address: { city: 'Portland', country: 'USA' },
interests: []
}
| Field | Type | Notes |
|---|---|---|
_id |
integer | 1 to 12 |
name |
string | |
email |
string | missing for customers 4, 8 and 12 |
tier |
string | gold, silver or standard |
joined |
date | between January and May 2026 |
address |
embedded document | city and country |
interests |
array of strings | may be empty |
orders
An order embeds its line items. Each item copies the product's name and price at the moment of purchase, so the order stays correct even if the product's price changes later:
print(db.orders.findOne({ _id: 1002 }));{
_id: 1002,
customerId: 3,
date: ISODate('2026-03-02T15:30:00.000Z'),
status: 'delivered',
items: [
{ productId: 3, name: 'Ethiopia Yirgacheffe', qty: 1, price: 27 },
{ productId: 17, name: 'Dark Chocolate Bar', qty: 4, price: 4.5 }
],
total: 45
}
| Field | Type | Notes |
|---|---|---|
_id |
integer | 1001 to 1020 |
customerId |
integer | refers to customers._id |
date |
date | 1 March to 3 June 2026 |
status |
string | delivered, shipped, processing or cancelled |
items |
array of documents | productId, name, qty, price |
total |
number | sum of qty × price over the items |
Customers 4, 8 and 12 have never ordered. The order statuses break down like this:
for (const status of ['delivered', 'shipped', 'processing', 'cancelled']) {
print(status.padEnd(10), db.orders.countDocuments({ status }));
}delivered 10
shipped 3
processing 5
cancelled 2
Tip: Want to try an example on your own machine? Copy the seed script into mongosh with
load('seed.js')in an empty database, then paste the example.
Test yourself
Where are the line items of an order stored?
- In a separate
itemscollection - Embedded in the order document as an array
- In the product documents
- Only the total is stored
If an example deletes every product, what does the next example see?
- No products
- The full sample data again
- Only the products it inserted
- An error