MapReduce is popular with the concept of "big data".
In fact, the concept of MapReduce is very simple,
Functionally, a group operation that is equivalent to an RDBMS
What are the real strengths of MapReduce?
A: Distributed, when the data is very large, like Google, there are n multi-data centers,
The data are not at one end of the Earth, with group grasp.
Since the group does not support distributed, the computing power of a single server is bound to be limited.
While Maprecuce supports distributed, supporting a large number of servers to work simultaneously,
Use brute force to count.
Maprecuce's working process:
①map:
This is called the mapping function, which calls emit (Key,value), and the collection is grouped according to the key you specify.
②reduce:
This is called the simplification function, the data grouped by the map is grouped to simplify, note: The key in reduce (Key,value) is emit in the key,value for the emit grouping of emit (value), the array (the same group) of the data, the operation .
Calculate the total inventory for each column with MapReduce
Map function
var map = function () {
Emit (This.cat_id,this.goods_number);
}
var reduce = function (cat_id,numbers) {
return array.sum (numbers);
}
Db.goods.mapReduce (map,reduce,{out: ' Res '});
Results are saved to "res"
Db.res.find ()
#用mapReduce计算每个栏目下商品的平均价格
var map = function () {
Emit (This.cat_id,this.shop_price);
}
var reduce = function (cat_id,values) {
return Array.avg (values);
}
Db.goods.mapReduce (map,reduce,{out: ' Res '});
Use of the MapReduce function for MongoDB aggregation operations (11)