Learn MongoDB
MongoDB rewards good data modelling. These quizzes cover querying, updates and the design and performance decisions that matter in real projects.
Commands shown in mongosh syntax (MongoDB 6+).
What you will practise
- Querying and projecting documents
- Update operators
- Embedding versus referencing
- Indexes and the aggregation pipeline
MongoDB lesson
A short introduction to the ideas behind the quizzes, before you start practising.
MongoDB stores data as flexible JSON-like documents instead of rows in fixed tables. The main design skill is deciding when to nest related data inside a document (embedding) and when to keep it in a separate collection (referencing).
Key concepts
Documents and collections
A document is a single JSON-like record (BSON under the hood); a collection is a group of documents, roughly like a table, but documents in the same collection do not need identical fields.
db.users.insertOne({ name: "Asha", age: 21, tags: ["student"] });Querying with operators
Queries are JSON-shaped filters. Comparison operators like `$gt`, `$lt` and `$in` let you express conditions beyond simple equality.
db.users.find({ age: { $gte: 18 } });Embedding vs referencing
Embed data that is small, bounded and almost always read together with its parent (like an address inside a user). Reference data that is large, unbounded or shared across many documents (like a product referenced by thousands of orders), to avoid huge documents and duplicated updates.
// Embedded (read together, bounded):
{ name: "Asha", address: { city: "Pune" } }
// Referenced (unbounded, shared):
{ orderId: 1, productId: ObjectId("...") }Indexes
Without an index, MongoDB scans every document to satisfy a query. An index on the fields you filter or sort by lets it jump straight to matching documents, at the cost of extra storage and slightly slower writes.
db.users.createIndex({ email: 1 }, { unique: true });Common mistakes
- Embedding data that can grow without bound (like years of activity logs) inside a single document, pushing it toward the 16MB document size limit.
- Forgetting that updates without a query operator (like `$set`) replace the whole document instead of modifying a field.
- Not indexing fields used in frequent queries, leading to full collection scans on a growing dataset.
- Assuming MongoDB enforces a schema the way a relational database enforces column types, and skipping validation at the application level.
Quick recap
- A document is one flexible record; a collection groups documents loosely, without a fixed schema.
- Embed small, bounded, together-read data; reference large or widely shared data.
- Use query operators like $gte, $lt and $in for anything beyond exact equality.
- Add indexes for the fields your real queries filter or sort by.
Ready to test this? Take the MongoDB Basics quiz →
Roadmap
Work through the levels in order, or jump to where you are.
Intermediate
Modelling & performance
- Embed vs reference
- Indexes
- Aggregation
- Transactions
MongoDB quizzes
Interactive MongoDB challenges
Hands-on activities: find bugs, complete code, order steps and match concepts.
MongoDB articles
FAQ
Do I need to install MongoDB?
No. The quizzes are conceptual and show mongosh-style commands.