Module Review: Foundations

1. Key Takeaways

  • Document Model: MongoDB stores data in BSON (Binary JSON) format. This aligns with object-oriented code, eliminating the need for complex ORMs.
  • Flexible Schema: Unlike SQL, collections do not enforce a schema. You can evolve your data structure without downtime.
  • Scalability: MongoDB scales Horizontally via Sharding (distributing data across servers) and provides High Availability via Replica Sets.
  • Architecture:
  • mongod: The core database process.
  • mongos: The router for sharded clusters.
  • WiredTiger: The default storage engine (Compression + Document-Level Locking).

2. Interactive Flashcards

Click on a card to reveal the answer.

What is BSON?

Binary JSON. A binary-encoded serialization of JSON-like documents. It supports more data types (Date, ObjectId) and is faster to parse/traverse than plain JSON.

Replica Set vs Sharding?

Replica Sets provide High Availability (Redundancy) by copying data to multiple nodes. Sharding provides Scalability by partitioning data across multiple nodes.

What is WiredTiger's main concurrency advantage?

Document-Level Locking. It locks only the specific document being written to, allowing multiple threads to write to the same collection simultaneously.

What role does 'mongos' play?

It acts as a Query Router in a Sharded Cluster. The application connects to `mongos`, which directs the query to the correct Shard(s).

3. Cheat Sheet: SQL to MongoDB

Concept SQL (RDBMS) MongoDB
Namespace Table Collection
Record Row Document (BSON)
Field Column Field
Relations JOIN Embedding (preferred) or $lookup
Primary Key ID (often Auto-Increment) _id (ObjectId by default)
Transactions Multi-Row ACID Single-Doc ACID (Multi-doc available)
Schema Enforced on Write Flexible / Dynamic

System Limits (Reference)

Item Limit Note
Document Size 16 MB If larger, use GridFS.
Nested Depth 100 Levels Avoid extremely deep nesting.
Index Name Length 128 chars Keep index names concise.
Namespace Length 120 bytes Database + Collection name length.

4. Next Steps

Now that you understand the architecture, it’s time to start working with data.