MongoDB Assignments — Model. Query. Scale.

Advance from “what is a document?” to production-grade data design and ops. Each topic-wise set includes 20 Basic, 20 Intermediate, and 10 Advanced questions so learners can practice deliberately and level up fast.

Your five attached assignments span: NoSQL foundations & BSON, CRUD & operators, aggregation/indexing & schema design, transactions/replication/security/backup, and sharding/Atlas/text/geo/time-series.

Why practice with these assignments?

  • Move beyond theory—create databases/collections, insert documents, query with operators, and visualize in Compass/Atlas.
  • Build real habits: projection/sort/limit/skip, aggregation pipelines, indexes with explain(“executionStats”), and validation.
  • Get ops-ready with transactions, write concerns, replica sets, backup/restore, profiling, and Atlas monitoring.

How it works

  • Open any assignment and attempt questions in order: Basic → Intermediate → Advanced.
  • Practice in mongosh + Compass; for cloud tasks, use a free Atlas cluster.
  • Validate results with find()/aggregation outputs, explain(), and logs/profiler where asked.
  • Keep a short “what I learned” note per task—this compounds quickly.

What you’ll achieve

  • A clear mental model of documents/BSON, databases/collections, and NoSQL trade-offs.
  • Fluency with CRUD and query operators ($and/$or/$in/$elemMatch/$exists, etc.) plus projections/sorting/pagination.
  • Practical aggregation skills ($match/$group/$project/$lookup/$facet) and indexing including compound/multikey.
  • Confidence with transactions, writeConcern/readPreference, replication, backup/restore, RBAC, and profiling.

Awareness of sharding, text search, geospatial, time-series, and Atlas ops (security, scaling, alerts).

Browse the Assignments

  • Foundations: NoSQL, Shell & BSON — create DB/collections, insert flexible docs, explore BSON types (ObjectId, Date, binary), Compass/Atlas setup.
  • CRUD & Query Operators — insertOne/Many, find/findOne, updates/deletes, comparisons & logicals, arrays/nested fields, projection/sort/limit/skip/distinct/count.
  • Aggregation, Indexing & Schema Design — $group/$avg/$sum, $lookup, pagination via $skip/$limit, compound & multikey indexes with explain, JSON Schema validators, modeling 1-1/1-N/N-N.
  • Transactions, Security & Replication — ACID multi-doc transactions, users/roles, backup/restore, replica sets, read preferences, write concerns, profiling slow queries.
  • Sharding & Atlas: Text/Geo/Time-series — enable sharding, shard keys & distribution, text search, 2dsphere queries, time-series collections, TLS/encryption, alerts, autoscaling.

Tips for success

  • Prefer indexed queries; measure with explain(“executionStats”) before/after adding indexes.
  • Use validators to keep data clean; start in validationAction: “warn” before enforcing “error”.
  • For multi-doc consistency, use transactions on replica sets and set writeConcern: “majority”.
  • In Atlas, secure by default: IP allowlists, TLS in transit, encryption at rest, role-based access.

Ready to build real confidence in MongoDB? Pick a set below and start solving!

FAQs

Q1. Which MongoDB edition should I use—local or Atlas?
Either works. Many tasks use mongosh and Compass locally, while cloud-based exercises use Atlas (the free tier is sufficient).

Q2. How do I verify that my queries are efficient?
Create or adjust indexes and compare results with explain("executionStats") before and after. Pay attention to keys examined versus documents returned.

Q3. Aggregation vs find()—when should I use which?
Use find() for simple filters and projections. Choose aggregation for grouping, joins with $lookup, multi-stage transformations, or paging with totals using $facet.

Q4. Should I embed or reference?
Embed small, tightly coupled data that’s read together. Reference for large or volatile relations and for cross-collection reuse, then join with $lookup when needed. You’ll practice both designs.

Q5. Do I need a replica set for transactions?
Yes. Multi-document transactions require a replica set (or a sharded cluster). The assignments include both single-document atomicity and full ACID transactions with write concerns.

Q6. What are writeConcern and readPreference?
writeConcern controls durability (for example, “majority”), while readPreference determines where reads go (primary, secondary, or nearest). You’ll practice both in replica set exercises.

Q7. How do I profile and diagnose slow queries?
Enable profiling with thresholds such as 100ms, inspect profiler output, and compare with explain(). In Atlas, the Performance Advisor also suggests indexes.

Q8. Any pitfalls with indexing?
Too many or poorly chosen indexes can slow writes and increase storage use. Measure carefully and prune unused indexes. One assignment focuses on this trade-off.

Q9. When should I shard?
Shard when a single node cannot handle the data volume or throughput. You’ll enable sharding, choose keys (range vs hashed), inspect distribution, and test resharding patterns.

Q10. How do I secure a deployment?
Enable authentication, create least-privilege roles, lock down IP addresses, and enforce TLS in transit and encryption at rest. Atlas provides these features by default.