MongoDB Terminology
Every MongoDB tutorial throws the same five words at you in the first minute. Learn them once, map them to what you already know, and the rest of this course reads easily.
The rule
Databases hold collections, collections hold documents, and every document has an
_id.
| MongoDB | Relational cousin | Bookshop example |
|---|---|---|
| database | database | bookshop |
| collection | table | books |
| document | row | one book |
| field | column | title |
_id |
primary key | 1 |
A few rules make the words precise:
_idis required and unique in its collection. If you insert a document without one, MongoDB adds an ObjectId, a 12-byte value that is unique in practice. You may choose your own_id(this course uses small numbers so examples stay readable). It cannot be changed after insert.- Collections and databases appear on first write.
use bookshopswitches to the name; the first insert creates both. - A collection has no fixed columns. Documents in it usually look alike, but they are allowed to differ.
Here is the running example for the whole course, the books collection:
| _id | title | author | year | price | stock | genres |
|---|---|---|---|---|---|---|
| 1 | Dune | Frank Herbert | 1965 | 9.99 | 12 | sci-fi, classic |
| 2 | Neuromancer | William Gibson | 1984 | 8.5 | 0 | sci-fi, cyberpunk |
| 3 | Emma | Jane Austen | 1815 | 4.25 | 7 | classic, romance |
| 4 | The Hobbit | J.R.R. Tolkien | 1937 | 7.99 | 3 | fantasy, classic, adventure |
| 5 | Circe | Madeline Miller | 2018 | 12 | 5 | fantasy, myth |
Each book also has a publisher object and most have a ratings array; later lessons show those in full.