mapReduce no output into result

MALTES Corto shared this question 5 years ago
Answered

hello, how do I get a result in the window when using the function mapReduce?


MySample : I have no output

var mapFunc = () => {

emit(this.Name, 1);

};

var reduceFunc = (key, values) => {

return Array.sum(values);

};


db.MyCollection.mapReduce( mapFunc, reduceFunc,{out: { "inline":1 }});


thx

Best Answer
photo

Please modify your code as follows and try it again.

var mapFunc =function() { //Arrow functions are anonymous and change the way this binds in functions.

emit(this.Name, 1);
};

var reduceFunc = function(key, values) {
   return Array.sum(values);
};

db.MyCollection.mapReduce( mapFunc, reduceFunc,{out: { "inline":1 }});

Replies (2)

photo
2

Please modify your code as follows and try it again.

var mapFunc =function() { //Arrow functions are anonymous and change the way this binds in functions.

emit(this.Name, 1);
};

var reduceFunc = function(key, values) {
   return Array.sum(values);
};

db.MyCollection.mapReduce( mapFunc, reduceFunc,{out: { "inline":1 }});

photo
1

perfect it works, thank you

Leave a Comment
 
Attach a file