The dashboard card
The owner's dashboard shows, per day, the number of served orders, revenue, and the best-selling dish. Build it as one aggregation pipeline.
Plan the pipeline
The dashboard card needs, per day, the number of served orders, the revenue and the top dish. That's two levels of grouping: first by day and dish to get each dish's quantity and revenue per day, then by day to total everything up and pick the best dish. Sorting by quantity before the second group lets $first pick the winner.
- $match served orders.
- $addFields day with $dateToString in Kathmandu time.
- $unwind items.
- $group by day + dish: quantity, revenue, order ids.
- $sort by day, then quantity descending.
- $group by day: orders, revenue, top dish with $first.
- $project the final shape and $sort by day.
Write and check the first group before adding the second.