The pick for flexible, varied data - once you've used a database before.
MongoDB stores data as JSON-like documents rather than rows in tables. Each document can have its own shape, so records with varied or evolving fields don't need a fixed schema decided up front.
You'll see MongoDB when your data is flexible or varied (documents, logs), you've used a database before or are comfortable with them, and you're not on shared hosting (where MongoDB is rarely available). If you're new to databases, Stack Picker deliberately steers you to SQL first - most "varied" data still fits tables fine, and SQL is the more transferable skill.
Good fits: product catalogues where a shoe, a laptop and a sofa each have different attributes; event and activity logs; CMS content with optional, nested fields; data you receive as JSON from other systems and mostly read back whole.
Poor fits: data that's heavily relational - customers, orders, products and invoices that you constantly combine in different ways. MongoDB can do lookups between collections, but if most of your queries are joins, a relational database will be simpler and safer.
Create a free cluster on MongoDB Atlas (its free tier is plenty for learning), copy the connection string, and try the official Node.js driver:
import { MongoClient } from "mongodb";
const client = new MongoClient(process.env.MONGODB_URI);
const products = client.db("shop").collection("products");
await products.insertOne({
name: "Trail running shoe",
price: 89,
tags: ["running", "outdoor"],
specs: { weightGrams: 280, drop: "6mm" },
});
const cheapOutdoor = await products
.find({ tags: "outdoor", price: { $lt: 100 } })
.toArray();
console.log(cheapOutdoor);
await client.close();
Notice that tags: "outdoor" matches any document whose tags array contains that value - a query that needs a separate table in SQL. From here, wrap the queries in an Express API, add products with completely different specs, and add an index on tags.
PostgreSQL's JSONB columns let you store and index flexible JSON alongside normal relational tables. If your data is mostly structured with some variable parts, that hybrid is often the better choice - see the PostgreSQL pick.