Starting from version 2.4 MongoDB uses the V8 engine, thus ECMA-262 5th edition. When running MapReduce jobs inside the shell, there is a list of additional supported function.
What If I use the native Node.js driver to run a mapReduce job? Will I be able to use any module or JavaScript function inside map and reduce?
Edit: I can't do some tests right now to figure it out, but I'll update the question ASAP.
MapReduce runs within the MongoDB instance.
You can't use any other programming language or platform to create a MapReduce right now. You could simulate the concept I suppose, but it would mean all data was transferred to your application, etc.
The body of the function is transferred from the Node.JS process to MongoDB (and shards, etc.) by calling toString on the provided map function (see here).
if ('function' === typeof map) {
map = map.toString();
}
You could embed functions in the map function, but you'd want to confirm that the performance met your needs as the complexity of the function increases. But, it still would be limited to the function you passed, and could not access other script in Node.JS that might be executing.
Edit:
Also, you could use the scope parameter of the mapReduce call to attach additional functions. If for example, you passed a scope as:
{ add10: function(v) { return v + 10; } }
The function called add10 would be available in the map call (and also the reduce and finalize functions):
var fancyMath = add10(this.total);
So, using that technique, you could pass some limited functionality. It does get serialized as BSON and sent to the MongoDB servers, so it needs to be self-contained (and not reference other JavaScript functions that won't be available locally).