Internet Engineering
NoSQL · Distribution · MongoDB · Documents · Operations
Fall 2026 ·
Amirkabir University of Technology
@1995parham
Originally presented by Ehsan Edalat and Parham Alvani. The original slides are also available as a PowerPoint file.
The same data on several servers. If the primary disappears, the members elect a new one, so failover needs no operator.
Horizontal scale: one logical database split by a shard key. A poor key sends every query to every shard, or every write to one shard.
| RDBMS | MongoDB |
|---|---|
| Database | Database |
| Table, View | Collection |
| Row | Document (BSON) |
| Column | Field |
| Index | Index |
| Join | Embedding, or $lookup |
| Primary key | _id |
mongod: the database servermongos: the router in front of a sharded
clustermongosh: the shell, a full JavaScript
environment
{ "_id": 1, "name": "R2-D2", "race": "Droid", "affiliation": "rebels" }
{ "_id": 2, "name": "Han Solo", "ship": "Millennium Falcon" }
Model for the queries you will run, not for the tidiest normal form.
// create
db.students.insertOne({ name: "Parham", id: "9231058" });
db.students.insertMany([{ name: "Ali" }, { name: "Sara" }]);
// read
db.students.find({ name: "Parham" });
db.students.findOne({ id: "9231058" });
// update
db.students.updateOne({ id: "9231058" }, { $set: { name: "Parham Alvani" } });
// delete
db.students.deleteOne({ id: "9231058" });
Documents flow through stages, each one transforming the stream.
// keep the big courses, count them per teacher, busiest first
db.courses.aggregate([
{ $match: { capacity: { $gt: 20 } } },
{ $group: { _id: "$teacher", total: { $sum: 1 } } },
{ $sort: { total: -1 } },
]);
const studentSchema = new mongoose.Schema({
name: { type: String, required: true },
id: { type: String, unique: true },
});
const Student = mongoose.model("Student", studentSchema);
