Mongo Map-Reduce

with No Comments

It was task about searching and grouping demographic user data.
User demographic data is saved in AnalysisData.
Each demographic section (Gender, Family Status) has Its own items. For example, section “Family Status” has items “Parents”, “Married”, “Single”.

Let’s say we have a query: ( = “Male” and items.percentOfItem > 40%) and ( = “Married” and sizeOfItem > 6000
The result of the work should be table with following data:

1 40.8% 6093

A Mapper will start off by reading a collection of data and building a Map with only the required fields we wish to process and group them into one array based on the key. And then this key value pair is fed into a Reducer, which will process the values.

In our case key is fanId, value is items. Required fields are items under the names Male or Marries.

After Map-Reduce operation data will be in such view and now it possible apply query:

MapReduce queries can be used to construct large complex aggregation queries. It’s easy to understand and easy to use;)

Leave a Reply