I'm looking for good ideas to organize my js code around mongo with the difficulty that map reduce functions cannot use the client scope so all functions must be sent (or saved) to the server (hard to reuse existing code). I could use server stored function but as we have a db/client system is a too large scope and db scoped function does not seem to be possible.
Other idea is to use a javascript preprocessor, something like that :
var mapFunction = function() {
// @include lib.js
Lib.foo(this.bar);
}
lib.js :
var Lib = {
foo : function(bar) {...}
}
and run the generated mapFunction within a mapReduce command.
Is there any good practices/ideas to achieve good code reuse (without system stored functions) inside mongodb map/reduce javascript codebase?