MongoDB Tutorial 0/120 lessons ~6 min read Lesson 112
Mock Database Interviews
These mock interviews simulate the structure of real backend / data engineering loops: a short live-coding pipeline, a system-design segment, and a postmortem question.
Course progress0%
Focus
4 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
These mock interviews simulate the structure of real backend / data engineering loops: a short live-coding pipeline, a system-design segment, and a postmortem question. Time each section — the constraint is part of the practice.
You'll find walkthrough answers for the first two; the others are intentionally left for you to write up and review with a peer.
Understanding the topic
3 timed interview rounds:
- R1 (30 min) — live aggregation: cohort retention by signup month.
- R2 (45 min) — system design: SaaS ticketing platform on MongoDB for 10k tenants.
- R3 (30 min) — postmortem: primary failed over twice in a week; describe your investigation.
Informative example
R1 walkthrough — cohort retention:
js
db.events.aggregate([{ $match: { type:"login" } },// 1) attach signup month to every event{ $lookup: { from:"users", localField:"userId", foreignField:"_id", as:"u" } },{ $unwind: "$u" },{ $set: { cohort: { $dateTrunc:{ date:"$u.createdAt", unit:"month" } },eventMonth: { $dateTrunc:{ date:"$ts", unit:"month" } } } },// 2) months since signup{ $set: { monthOffset: { $dateDiff:{ startDate:"$cohort", endDate:"$eventMonth", unit:"month" } } } },// 3) unique active users per (cohort, offset){ $group: { _id:{ cohort:"$cohort", offset:"$monthOffset" }, users:{ $addToSet:"$userId" } } },{ $project: { _id:0, cohort:"$_id.cohort", offset:"$_id.offset", active:{ $size:"$users" } } },{ $sort: { cohort:1, offset:1 } }]);
Best practices
- Always restate the question before coding — interviewers grade understanding first.
- Sketch the data model before writing the pipeline.
- Call out time/space trade-offs explicitly — even when not asked.
Ready to mark this lesson complete?Track your journey across the entire course.