DEV Community

Cover image for MongoDB Aggregation Pipeline Challenge - Challenge 21
Hello Dev World Blog
Hello Dev World Blog

Posted on • Originally published at hellodevworld.com

MongoDB Aggregation Pipeline Challenge - Challenge 21

Another Challenge!

Big Ice Cream Co is the largest ice cream franchisor in the US. Each of their 100+ franchisees has between 1 and 25 locations. Each location tracks its customer satisfaction score which can be below average, average, or above average. The CEO of Big Ice Cream Co wants to see a report that shows the customer satisfaction scores for each location grouped by franchisee.

Example:

| franchiseeId | franchiseeName | belowAverage | average | aboveAverage | totalLocations |

|---------------------|---------------:|--------------|---------|--------------|----------------||

search | True | 1 | 10 | 14 | 25 ||

institutionCodes | False | 10 | 3 | 0 | 13 ||

aggregatorPartnerId | True | 0 | 3 | 0 | 3 |

This data is stored in the franchising MongoDB, there are two collections:

  1. franchisee

  2. locations

Franchisee schema

{
    companyName: { type: String },
    signedDate: { type: Date },
    owner: { type: String }
}
Enter fullscreen mode Exit fullscreen mode

Locations Schema

{
    franchiseeId: { type: ObjectId },
    address: {
        state: { type: String },
        city: { type: String },
        zip: { type: String },
        streetAddress: { type: String },
        secondaryAddress: { type: String }
    },
    customerSatisfactionScore: { type: String, enum : ['below average','average', 'above average'] }
}
Enter fullscreen mode Exit fullscreen mode

As usual, I will be posting the solution in another post! I will post this solution with an explanation tomorrow!

Top comments (0)