All academies
All challenges

One-pass dashboard

hard+90 XP

Use $facet to compute two things in one pipeline: byCategory (count per category) and priceStats (single doc with avg price as avgPrice). Facet keys: byCategory, priceStats.

Sample of shop.products

{
  _id: 1,
  name: "Wireless Mouse",
  category: "electronics",
  price: 29.99,
  stock: 120,
  rating: 4.5,
  tags: [
    "wireless",
    "accessories"
  ]
}
{
  _id: 2,
  name: "Mechanical Keyboard",
  category: "electronics",
  price: 89.99,
  stock: 45,
  rating: 4.8,
  tags: [
    "mechanical",
    "rgb"
  ]
}
{
  _id: 3,
  name: "USB-C Hub",
  category: "electronics",
  price: 39.99,
  stock: 200,
  rating: 4.2,
  tags: [
    "usb",
    "accessories"
  ]
}