Database Overview
The foundations: databases, the main database types, SQL and NoSQL.
Learn MongoDB step by step, from what a database is to backups and replica sets in production. Plain explanations, hands-on mongosh commands and Java examples, updated for MongoDB 8.0.
MongoDB is a general-purpose document database. Instead of rows in tables, it stores data as flexible, JSON-like documents that look just like the objects in your code. It adds powerful queries and aggregation, indexes, automatic failover with replica sets, horizontal scaling with sharding, and ACID transactions, which is why it runs everything from small side projects to some of the largest applications in the world.
explain()Students and beginners new to databases, Java and Spring Boot developers adding MongoDB to their stack, and engineers preparing for interviews.
Basic computer and command-line skills. Some JavaScript or Java helps with the code examples, but the first tracks need no programming at all.
A MongoDB deployment holds databases; each database holds collections; each collection holds documents. Documents in the same collection can have different fields, and each one has a unique _id.
Follow the tracks in order, or jump straight to the topic you need. Each tutorial explains the idea in simple words and then shows working commands.
The foundations: databases, the main database types, SQL and NoSQL.
What MongoDB is, what it can do and how it compares with MySQL.
Create and remove databases, with naming rules and safety tips.
Validation, time series, capped and clustered collections, views and renames.
Insert, query, update and delete documents, with operators and Java examples.
Performance, high availability and protecting your data.
A command cheat sheet and 40 interview questions with answers.
Run MongoDB 8.0 locally with Docker, connect with mongosh and store your first document. (Prefer the cloud? Create a free cluster on MongoDB Atlas and use its connection string instead.)
docker run -d --name mongo8 -p 27017:27017 mongo:8.0
docker exec -it mongo8 mongosh
use bookstore
db.books.insertOne({ title: "Practical Java Streams", category: "Java", price: 499 })
db.books.find({ price: { $lt: 600 } })
db.books.updateOne({ title: "Practical Java Streams" }, { $inc: { price: -50 } })
db.books.countDocuments()
The bookstore database and books collection were created automatically by the first insert. Continue with the MongoDB Introduction to understand what just happened.
Documents map directly to objects in code, with nested fields and arrays, so there is no translation layer.
Add fields without migrations, and enforce rules with JSON Schema validation where it matters.
Filter on any field, aggregate with pipelines, and add full-text and vector search on Atlas.
Replica sets keep copies on several servers and fail over automatically within seconds.
Sharding spreads data and writes across many servers as your application grows.
ACID transactions, role-based access control, TLS and Queryable Encryption.
Most relational ideas have a direct MongoDB equivalent:
| SQL | MongoDB |
|---|---|
| Database | Database |
| Table | Collection |
| Row | Document |
| Column | Field |
SELECT … WHERE | find({ … }) |
INSERT / UPDATE / DELETE | insertOne() / updateOne() / deleteOne() |
GROUP BY | $group in an aggregation pipeline |
JOIN | Embedded documents or $lookup |