I'm currently exploring the potential of map-reduce in order to better grasp its utility.
Within my database, I have a collection titled "actions" containing 100k documents structured like this:
{
"profile_id":1111,
"action_id":2222
}
My aim is to conduct some map-reduce examples to generate a list of all users along with the total number of actions each user has taken. Is this achievable? Here's the code snippet I've been using:
db.fbooklikes.mapReduce(
function(){
emit(this.profile_id, this.action_id);
},
function(keyProfile, valueAction){
return Array.sum(valueAction);
},
{
out:"example"
}
)
Unfortunately, this approach isn't producing the desired outcome. The result obtained is as follows:
"counts" : {
"input" : 100000,
"emit" : 100000,
"reduce" : 1146,
"output" : 13
},
"ok" : 1,
"_o" : {
"result" : "map_reduce_example",
"timeMillis" : 2539,
"counts" : {
"input" : 100000,
"emit" : 100000,
"reduce" : 1146,
"output" : 13
},
"ok" : 1
},
Do you think what I'm attempting to achieve with map-reduce is feasible?