-
Notifications
You must be signed in to change notification settings - Fork 0
/
zapytanie_1_MR.js
51 lines (31 loc) · 1006 Bytes
/
zapytanie_1_MR.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var mapFunction = function () {
var key = this.sex;
var value = { height: this.height, weight: this.weight, count: 1, };
emit(key, value);
};
var reduceFunction = function (keySex, valuesHW) {
var reducedValRF = { height: 0.0, weight: 0.0, count: 0 };
valuesHW.forEach(function (value) {
reducedValRF.height += value.height;
reducedValRF.weight += value.weight;
reducedValRF.count += value.count;
});
return reducedValRF
};
var finalizeFunction = function (key, reducedValFF) {
var returnedValue = {
avg_weight: reducedValFF.weight / reducedValFF.count,
avg_height: reducedValFF.height / reducedValFF.count,
count: reducedValFF.count
}
return returnedValue;
};
db.people.mapReduce(
mapFunction,
reduceFunction,
{
out: "map_reduce_example",
finalize: finalizeFunction
}
)
db.getCollection('map_reduce_example').find()