MongoDB stores documents — flexible JSON-like objects — grouped into collections. There are no fixed columns; a document can contain arrays and nested objects. That flexibility is exactly why aggregation pipelines are so powerful later.
_idRun this to see one product document. Notice it holds a whole array (tags)
inside a single record — no separate "tags table" needed:
_id
It's the primary key — unique within the collection. In real MongoDB it's usually an
ObjectId (a 24-char hex value); here we use simple numbers to keep things readable.
If you insert without an _id, one is generated for you.
See a whole collection at once with find() and no filter:
| SQL word | MongoDB word |
|---|---|
| table | collection |
| row | document |
| column | field |
| primary key | _id |
SELECT … WHERE | find({...}) |
GROUP BY + joins | the aggregate([...]) pipeline |
Documents nest. An order holds an items array, and each item is itself a little document
with product, qty, price. To reach a nested field you use a
dotted path in quotes, like 'items.product'. Run this and look at the
shape of an order:
Now query by a value inside that array. Because items is an array of objects,
{ 'items.product': 'Latte' } matches any order containing a Latte item:
items.product without quotes is invalid JavaScript. Always write nested keys as strings:
{ "items.product": "Latte" }. Single-word keys like price don't need quotes.
_id?_id. Omit it on insert and MongoDB generates one.