How do I return group results by multiple fields in MongoDB?
问题 In MongoDB, the aggregate query below gives the average price per product-category, where business-name is "Foobar Inc" . var match = { $match: {"businessName": "FooBar Inc"}, ; var group = { $group: { _id: "$productCategory", total: { $avg: "$price" }}} var results = await db.aggregate("productsCollection", limit, match, group); Example object from productCollection : {"businessName": "FooBar Inc.", "productCategory": "toys", "price":88} Output: [{"_id": "shoes", "total":97}, {"_id": "toys",