Skip to content

Question 21 / 50

Must KnowHardDebuggingAggregation

This pipeline was acceptable at 100k orders and is now painful at 50 million. What would you investigate, in order?

db.orders.aggregate([
  { $lookup: { from: "users", localField: "userId", foreignField: "_id", as: "user" } },
  { $match: { status: "completed", "user.city": "Bangalore" } },
  { $group: { _id: "$userId", total: { $sum: "$amount" } } },
  { $sort: { total: -1 } }
])
Think about it first.