A document database for flexible, evolving data shapes.
MongoDB is a document database: instead of rows in tables with a fixed set of columns, data is stored as JSON-like documents grouped into collections. Two documents in the same collection don't need identical fields, which makes MongoDB a natural fit for data whose shape varies or evolves — logs, content with optional fields, or catalogs where different items have different attributes.
It contrasts directly with a relational database like PostgreSQL or MySQL, where every row in a table shares the same columns and relationships are enforced by the schema itself.
MongoDB fits content with varied or nested structure — product catalogs with different attributes per category, user-generated content, or event/log data — where forcing everything into uniform rows and columns would mean constant schema migrations. It's less of a natural fit for data with lots of relationships between entities (orders linked to users linked to products), where a relational database's joins and constraints do a lot of the correctness work for you. For most beginner projects with structured data — users, orders, posts — MySQL or SQL fundamentals are the better place to start, since they transfer to almost every other database too.
ALTER TABLE-style
migration affecting existing ones.
GROUP BY and joins
but expressed as a pipeline of stages.
const doc = await db.collection("posts").insertOne({
title: "Hello Mongo",
tags: ["intro", "database"],
author: { name: "Ada", verified: true },
});
const posts = await db
.collection("posts")
.find({ tags: "intro" })
.toArray();
Notice the nested author object and the
tags array living directly inside the document —
no separate "authors" or "tags" table required.
npm install mongodb and connect using your Atlas
connection string.