var map function var key year this date getFullYear month this date ge

 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
var map = function() {
var key = {
year: this.date.getFullYear(),
//month: this.date.getMonth(),
day: this.date.getDate()
};
key['domain'] = this.domain;
key['stat'] = "yandexCitation";
emit(key, this.stats.yandexCitation);
key['domain'] = this.domain;
key['stat'] = "pageRank";
emit(key, this.stats.pageRank);
key['domain'] = this.domain;
key['stat'] = "yandexIndex";
emit(key, this.stats.yandexIndex);
key['domain'] = this.domain;
key['stat'] = "googleIndex";
emit(key, this.stats.googleIndex);
};
var reduce = function(key, values) {
function median(values) {
values.sort( function(a,b) {return a - b;} );
var half = Math.floor(values.length/2);
if(values.length % 2)
return values[half];
else
return (values[half-1] + values[half]) / 2.0;
}
return median(values);
};
db.SitesHistory.mapReduce(map, reduce, {
out: { inline: 1 }
});