Moj kod:
db.dvdrent.mapReduce(
`function(){
if(this.film != undefined){
if(this.film.actors != undefined && this.film.categories != undefined){
var filmTitle = this.film.title;
var actorsId = [];
this.film.actors.forEach(function(actor){
actorsId = actorsId.concat(actor.actor_id)
});
this.film.categories.forEach(function(category){
emit(category, {films : [{title:filmTitle, actorsId:actorsId}] });
});
}
}
};`,
`function(key, values){
var rv = {
films : []
}
values.forEach(function(value){
rv.films = rv.films.concat(value.films)
});
return rv;
};`,
{ "finalize" : `function(key, reducedValues){
reducedValues.films = reducedValues.films.filter((item, pos, self) =>
pos === self.findIndex((t) => (
t.title === item.title
))
);
var allActors = [];
reducedValues.films.forEach(function(value){
allActors = allActors.concat(value.actorsId)
});
var uniqueActors = new Set(allActors);
var all = allActors.length;
var unique = uniqueActors.size;
return {"all":all, "unqiue":unique};
};`
}
)
Ako neko ima rješenje zadatka ili može pomoć pronaći grešku pls?