Get Started Free

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

Core

Joins, grouping, arrays, types and geo. Warm-up to solid mid-level.

  1. 1The overstock list$sum on arrays$project$match after $projectMedium
  2. 2Best repeat customers$group$lookupDecimal128Medium
  3. 3One field, three types$type$switchschema driftMedium
  4. 4Price bands and how they are rated$bucket$lookupweighted averageMedium
  5. 5The order funnel$unwind$map$rangeHard
  6. 6Revenue by department$unwindtwo $lookupstree pathsHard
  7. 7Deliveries near Berlingeospatial$geoWithin$centerSphereMedium
  8. 8Who went quiet?$lookup with pipelineanti-joindatesHard
  9. 9Do supplier ratings hold up?$lookup$groupcomparing sourcesMedium
  10. 10They hated it, then bought it againcorrelated $lookup$in on arraystime orderingHard

Advanced

Trees and graphs, window functions, percentiles, calendars, market-basket.

  1. 11Broken timelines$range$map over pairs$dateDiffHard
  2. 12How long does delivery really take?$filter$dateDiff$medianHard
  3. 13Roll products up the category tree$graphLookuptrees$lookup with $inHard
  4. 14Chain of command$graphLookupdepthField$sortArrayHard
  5. 15Support team workload$graphLookup$replaceRootleft joinHard
  6. 16Referral downline$graphLookuprecursivedepthHard
  7. 17Revenue lost to cancellations, month by monthcalendar gaps$range$setWindowFieldsExpert
  8. 18Top 2 sellers in every category$setWindowFields$rankpartitionsExpert
  9. 19Days of coverdate ranges$unwindratesHard
  10. 20Frequently bought togetherself-join inside a documentdouble $unwindmarket basketExpert
  11. 21Longest gap between orders$setWindowFieldspartitionBy$shiftExpert
  12. 22Time to first order by sign-up cohortcohorts$lookup$medianExpert

Performance

The answer is the index and the query. Graded on the result and the explain plan.

  1. 23The right compound index (ESR)indexesEquality-Sort-RangeexplainHard
  2. 24Answer from the index alonecovered queriesprojectionexplainHard
  3. 25Paris has more than 50$elemMatchmultikey indexescorrectnessExpert
  4. 26Search-as-you-type on emailregexindex boundsexplainMedium
  5. 27Page 6 without skippaginationkeyset / seek methodtie-breakersExpert
  6. 28Do not wrap the indexed fieldaggregationindex use$expr pitfallsHard
  7. 29Which side should the join start from?$lookup costjoin orderindexes for $lookupExpert
  8. 30Count without reading documentsCOUNT_SCANcovered countexplainHard

The dataset

Every question uses this database. Open a collection to see its fields.

categories18 docs
_idObjectId
namestring
parentIdnull | ObjectId
pathstring
suppliers6 docs
_idObjectId
namestring
countrystring
ratingdouble
sincedate
products26 docs
_idObjectId
skustring
namestring
categoryIdObjectId
supplierIdObjectId
pricedecimal
tagsarray of string
stockarray of objects
warehouse qty
activeboolean
createdAtdate
customers30 docs
_idObjectId
namestring
emailstring
tierstring
addressesarray of objects
type street city country zip location
preferencesobject
newsletter currency
lifetimeValuedecimal
joinedAtdate
marketingOptInboolean
phonestring, 24 of 30
lastLogindate, 15 of 30
externalRefint | string, 10 of 30
loyaltyPointsint, 18 of 30
referredByObjectId, 17 of 30
orders220 docs
_idObjectId
numberstring
customerIdObjectId
placedAtdate
statusstring
statusHistoryarray of objects
status at
itemsarray of objects
productId sku name qty unitPrice
shippingobject
type street city country zip location method
totaldecimal
currencystring
supportAgentIdObjectId, 33 of 220
notestring, 33 of 220
reviews87 docs
_idObjectId
productIdObjectId
customerIdObjectId
orderIdObjectId
ratingint
commentstring
atdate
employees9 docs
_idObjectId
namestring
titlestring
reportsTonull | ObjectId

VisuaLeaf for MongoDB

Write these queries visually on your own data

VisuaLeaf's query builder, aggregation builder and explain plan viewer work against your real MongoDB, Atlas or DocumentDB.