Transforms a collection into a collection of aggregated groups, by applying a supplied element-mapping function to each element, that transforms each one into a key-value pair, grouping the resulting pairs by key, and finally reducing values in each group applying a suppling 'reduce' function.
Each supplied function is coded in JavaScript. Note that the correct way of writing those functions may not be obvious; please consult MongoDB documentation for writing them.