From the course: MongoDB Aggregation Pipeline: Advanced Data Analysis and Manipulation
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Custom aggregation functions - MongoDB Tutorial
From the course: MongoDB Aggregation Pipeline: Advanced Data Analysis and Manipulation
Custom aggregation functions
- [Instructor] We've learned a lot about the MongoDB aggregation framework so far. Up until now, we've relied on aggregations and stages provided by MongoDB to build our pipelines. While these aggregators cover a majority of use cases, they may come a time where the provided aggregators just don't suit your use case. This is where the $function and $accumulator aggregators come in. They allow you to implement a custom aggregator directly in your aggregation pipeline. In this video, we'll take a look at writing a custom $function aggregator. The $function aggregator allows us to write a JavaScript function to implement custom behavior. We can combine this aggregator with various pipeline stages to get the result we want. For our example, let's say we wanted to give our customers expected shipping times based on their location. Customers with lowered numbered zip codes will get their order sooner. And trying to do this…