Get Started Free

4. Price bands and how they are rated Solved

CoreMedium$bucket$lookupweighted average

Group products into price bands [0, 5), [5, 20), [20, 50) and 50+. For each band return the number of products, the number of reviews they received, and avgRating: the average of all review ratings in the band (not the average of per-product averages), rounded to 2 decimals, or null if the band has no reviews.

Your answer returns 4 documents with the fields avgRating, band, products, reviews. Order matters.

The data

The shop database from the MongoDB playground, running in your browser. "Today" is 2026-11-18.

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

Hints

Common traps
  • Average of averages: a product with 1 review would weigh as much as one with 20.

Solution

Run in the shell with Ctrl/⌘ + Enter. Check with Shift + Ctrl/⌘ + Enter.

"Check answer" runs your shell code on a fresh copy of the data, then on 2 hidden test datasets with more customers and orders, and compares each result with the expected one. The value of your last line is your answer.

Starting…