0

I'm writing a map reduce in MongoDB to remove duplicates words from the stuff array:

reduce = function(key, stuff){ 
                              var x = stuff.toString();
                              var z = Array.from( new Set(x.split(','))).toString(); 
                              return z
                             };

MongoDB gets an error:

MR processing failed: { errmsg: \"exception: ReferenceError: Set is not defined\n at _funcs2 (_funcs2:1:84) near 'from( new Set(x.split(',')).toString()); ' \", code: 16722, ok: 0.0 }"}

I'm using MongoDB 3.0.9.

harry-potter
  • 1,981
  • 5
  • 29
  • 55
  • The `Set` object is a new feature in the ECMAScript 2015 (ES6) standard which is not yet implemented by the Javascript engine of MongoDB before version 3.2. Possible duplicate of [Remove Duplicates from JavaScript Array](http://stackoverflow.com/questions/9229645/remove-duplicates-from-javascript-array) – Philipp Mar 03 '16 at 16:18
  • As stated `Set` is likely not available to the engine being used to process. Also "stringifying" the values array is a real hack. Just output as `{ "array": [ ... ] }` in your emit and reduce and handle accordingly. If indeed you really need mapReduce ( and odds are on that you don't ) in the first place. It's better to show the whole process you are trying to achieve as a question, since that way you might learn a better approach. As the question stands, we can only correct syntax errors or state that new language features are not available. – Blakes Seven Mar 04 '16 at 00:39
  • I must use map/reduce, there aren't other choices. I didn't know Set is not yet implemented in version 3.2 – harry-potter Mar 04 '16 at 09:14

0 Answers0