MongoDB in 8 Slides
Theme
Palette
Download
Caption (tap to copy)
📖 Deep dive (full written explanation)
This post is the entry point to MongoDB, so the cover deliberately answers the simplest question first: what is this thing? Before talking about scaling, indexes, or aggregation pipelines, you need a clear mental model of the basic unit of storage. Everything downstream — why it matters, how it works, the code, the mistakes — builds on the idea that Mongo stores documents, not rows.
Keep the framing concrete. You already know what a JSON object looks like; MongoDB essentially lets you store those objects directly and query them. That single shift is what makes the rest of the system feel different from a relational database.
The phrase 'document database' is the heart of the definition and it's worth slowing down on. A document is not a Word file or a PDF — in this world a 'document' is a structured record of field-value pairs, almost exactly the shape of a JSON object in your code. Collections group related documents the way tables group rows, but with a crucial difference: two documents in the same collection do not have to share the same fields.
The 'NoSQL' label confuses people. It does not mean 'no SQL allowed' or 'anti-relational dogma'. It means this family of databases stepped away from the strict relational table model to optimize for other things — flexible shape, horizontal scale, developer speed. MongoDB is the most widely used member of that family, which is why it's often the first NoSQL database engineers meet.
These three nouns — database, collection, document — are the vocabulary you'll use every single day, so anchoring them now pays off across the whole post series. A database is just a namespace that holds collections. A collection holds documents. A document is one record. That's the entire hierarchy, and it's intentionally shallow.
The part that trips up people coming from SQL is that a collection has no enforced schema. In a relational table every row has the same columns; in a Mongo collection one document can have a 'middleName' field and the next can omit it entirely. The value of a field can also be rich — an array, or a nested sub-document — which is what lets a single document represent an entire object graph that would span several joined tables in SQL.
This slide shows the payoff of the model in concrete form. The user, their list of roles, and their nested address all live inside one document. In a relational schema this would typically be three tables (users, roles, addresses) joined together at read time. Here it's one record you can fetch in one operation.
Notice the _id at the top and the ObjectId value — that's the primary key, covered two slides later. Also notice that 'roles' is an array and 'address' is an embedded object. This nesting is not an exotic feature; it's the normal, expected way to model data in MongoDB. When your access pattern is 'give me this whole user', storing it as one document is both simpler to write and faster to read.
The stack diagram makes the containment relationship visual: a database contains collections, a collection contains documents, and a document contains fields. Seeing it top-to-bottom helps cement that these are nested scopes, not parallel concepts.
A useful habit is to map this against the relational hierarchy you may already know — database, table, row, column — because the levels line up almost one to one. The difference isn't the number of levels; it's that the bottom levels (document and field) are flexible and can themselves nest, whereas rows and columns in SQL are flat and uniform.
BSON is one of those implementation details that quietly explains a lot of MongoDB's behavior. When you type a query in the shell it looks like JSON, but JSON itself is limited: it only knows strings, numbers, booleans, arrays, objects, and null. It has no real date type, no distinction between 32-bit and 64-bit integers, and no way to store raw binary efficiently.
BSON — Binary JSON — is MongoDB's on-disk and over-the-wire format. It encodes the same logical structure in a compact binary form and adds the missing types: Date, 64-bit ints, Decimal128, binary data, and ObjectId. It also length-prefixes fields so the engine can skip over parts of a document quickly. So while you think in JSON, the engine works in BSON, and that's why a date you store comes back as a real date and not a string.
The _id field is the one piece of structure MongoDB insists on: every document must have a unique _id within its collection, and it acts as the primary key. If you don't provide one, the driver or server fills it in for you with an ObjectId.
The ObjectId itself is clever. It's a 12-byte value whose first 4 bytes are a Unix timestamp, followed by a machine/process component and a counter. Two consequences fall out of that design: ObjectIds are roughly sortable by creation time, and they can be generated on any client without coordinating with a central server — which matters enormously when you're inserting from many machines at once. You can still supply your own _id (a UUID, an email, a natural key) when that suits your data better.
This comparison is the Rosetta Stone for anyone arriving from a SQL background. Table maps to collection, row to document, column to field. The first three rows are nearly exact translations and let you reuse intuition you already have.
The last two rows are where the models genuinely diverge. A JOIN across tables in SQL becomes, in Mongo, an embedded sub-document — you store the related data inside the parent rather than linking to it. And a fixed schema becomes a flexible one. Holding both columns in your head lets you read Mongo docs and tutorials without constantly re-learning vocabulary, and it flags exactly the two places where porting a relational design needs real rethinking rather than mechanical translation.
This snippet is deliberately minimal: insert one document, read it back, count the collection. It exists so the abstract definitions land as something you could actually type. insertOne takes a plain object — no column list, no schema declaration up front — which is the flexible-schema idea in action.
findOne takes a query document: you describe the shape of what you're looking for, and Mongo returns the first match. countDocuments confirms how many records exist. Three lines is enough to prove the core loop of any database — write, read, count — and it sets up the much deeper CRUD tour in post 4 of this day.
The recap compresses the whole post into five lines you could recite from memory. If a reader takes nothing else away, these are the load-bearing facts: it's a document database; the hierarchy is database to collection to document to field; documents nest arrays and sub-objects so you often don't need joins; the on-disk format is BSON; and every document has a unique _id.
The purpose of a tight recap on a foundational post is retention. The later posts assume this vocabulary, so a reader who internalizes these five points will follow the 'why', 'how', 'code', and 'mistakes' posts without getting lost.
This cover closes the concept post and points forward. Having established what MongoDB is, the natural next question is why anyone would choose it over the relational database they already know.
The teaser frames post 2 around stakes and trade-offs rather than features, which is the honest way to discuss any database. Flexibility and scale are real benefits, but they come with costs, and the next post treats both sides.