All challenges
Best-selling products
hard+80 XPEach order has an items array of { productId, qty }. Compute total quantity sold per productId as { _id: productId, sold: n }, sorted by sold descending.
Sample of shop.orders
{
_id: 1001,
userId: 101,
items: [
{
productId: 1,
qty: 2
},
{
productId: 3,
qty: 1
}
],
total: 99.97,
status: "delivered",
date: "2025-05-01"
}{
_id: 1002,
userId: 102,
items: [
{
productId: 5,
qty: 1
}
],
total: 199.99,
status: "shipped",
date: "2025-05-14"
}{
_id: 1003,
userId: 101,
items: [
{
productId: 9,
qty: 1
},
{
productId: 2,
qty: 1
}
],
total: 369.98,
status: "delivered",
date: "2025-06-02"
}