CoreHardcorrelated $lookup$in on arraystime ordering
Find customers who gave a product 2 stars or fewer and then ordered that same product again after the review (non-cancelled). Return customer, sku, rating, reviewedAt and reorderedAt (their first such re-order). Sort by customer, then sku.
Your answer returns 3 documents with the fields customer, rating, reorderedAt, reviewedAt, sku. Order matters.
The data
The shop database from the MongoDB playground, running in your browser. "Today" is 2026-11-18.
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 objects
warehouseqty
active
boolean
createdAt
date
customers30 docs
_id
ObjectId
name
string
email
string
tier
string
addresses
array of objects
typestreetcitycountryziplocation
preferences
object
newslettercurrency
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 objects
statusat
items
array of objects
productIdskunameqtyunitPrice
shipping
object
typestreetcitycountryziplocationmethod
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
Hints
Hint 1. A $lookup with let can see the review's customer, product and date at once.
Hint 2.{ $in: ["$$p", "$items.productId"] } checks whether an order contains the product.
Common traps
Matching any later order, not one that contains the reviewed product.
Free for personal practice. Please don't republish the questions or solutions. See the Playground License Terms.
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.