Vrba
db.dvdrent.mapReduce(
function () {
print(this.film);
if (this.film !== undefined) {
if (this.film.categories.length == 1) {
var hour = new Date(this.rental_date).getHours();
key = {
hour: hour
}
ct = {};
ct[this.film.categories[0].name] = 1;
value = {
categories: ct,
films: 1
}
emit(key, value);
}
}
}
,function (key, values) {
var rv = {
categories: {},
films: 0
}
values.forEach(value => {
rv.films += value.films;
for(var cat in value.categories) {
if(rv.categories[cat] !== undefined){
rv.categories[cat] += value.categories[cat];
} else {
rv.categories[cat] = value.categories[cat];
}
}
});
return rv;
}
)
S obzirom na CR, format ulaza u reduce() funkciju mora biti jednak njezinom izlazu.