MongoDB Interview Questions
30 hands-on practice problems that run on a real MongoDB-compatible database in your browser. Write the query, hit Check answer, and see right away if it's correct and, for the performance questions, if it's fast.
0 of 30 solved ยท saved in this browser
- A real datasetThe
shopdatabase: products, customers, 220 orders, reviews, suppliers, a category tree and an org chart. With the messy parts real data has. - Real mongoshWrite
find,aggregate,createIndexexactly as you would in the shell. Nothing to install, nothing leaves your browser. - Correct and fastEvery answer is checked against results verified on MongoDB 8. Performance questions also check the explain plan.
Core
Joins, grouping, arrays, types and geo. Warm-up to solid mid-level.
- 1The overstock listMedium
- 2Best repeat customersMedium
- 3One field, three typesMedium
- 4Price bands and how they are ratedMedium
- 5The order funnelHard
- 6Revenue by departmentHard
- 7Deliveries near BerlinMedium
- 8Who went quiet?Hard
- 9Do supplier ratings hold up?Medium
- 10They hated it, then bought it againHard
Advanced
Trees and graphs, window functions, percentiles, calendars, market-basket.
- 11Broken timelinesHard
- 12How long does delivery really take?Hard
- 13Roll products up the category treeHard
- 14Chain of commandHard
- 15Support team workloadHard
- 16Referral downlineHard
- 17Revenue lost to cancellations, month by monthExpert
- 18Top 2 sellers in every categoryExpert
- 19Days of coverHard
- 20Frequently bought togetherExpert
- 21Longest gap between ordersExpert
- 22Time to first order by sign-up cohortExpert
Performance
The answer is the index and the query. Graded on the result and the explain plan.
The dataset
Every question uses this database. Open a collection to see its fields.
categories18 docs
_id | ObjectId |
name | string |
parentId | null | ObjectId |
path | string |
suppliers6 docs
_id | ObjectId |
name | string |
country | string |
rating | double |
since | date |
products26 docs
_id | ObjectId |
sku | string |
name | string |
categoryId | ObjectId |
supplierId | ObjectId |
price | decimal |
tags | array of string |
stock | array of objectswarehouse qty |
active | boolean |
createdAt | date |
customers30 docs
_id | ObjectId |
name | string |
email | string |
tier | string |
addresses | array of objectstype street city country zip location |
preferences | objectnewsletter currency |
lifetimeValue | decimal |
joinedAt | date |
marketingOptIn | boolean |
phone | string, 24 of 30 |
lastLogin | date, 15 of 30 |
externalRef | int | string, 10 of 30 |
loyaltyPoints | int, 18 of 30 |
referredBy | ObjectId, 17 of 30 |
orders220 docs
_id | ObjectId |
number | string |
customerId | ObjectId |
placedAt | date |
status | string |
statusHistory | array of objectsstatus at |
items | array of objectsproductId sku name qty unitPrice |
shipping | objecttype street city country zip location method |
total | decimal |
currency | string |
supportAgentId | ObjectId, 33 of 220 |
note | string, 33 of 220 |
reviews87 docs
_id | ObjectId |
productId | ObjectId |
customerId | ObjectId |
orderId | ObjectId |
rating | int |
comment | string |
at | date |
employees9 docs
_id | ObjectId |
name | string |
title | string |
reportsTo | null | ObjectId |