All academies
All challenges

Revenue by status

hard+70 XP

Aggregate orders into { _id: status, revenue: total sum, orders: count }, sorted by revenue 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"
}