Effective Stored JavaScript in MongoDB
Vasil Remeniuk shares some tricks on working with MongoDB JavaScript:
This approach (nb: inlined JavaScript ) has two obvious drawbacks:
- Performance. Evaluated functions are not persisted between connects, therefore should be re-evaluated, which takes a lot of time (especially, if you deal with complex calls);
- Testability and readability. In-lined code is untestable and looks ugly.
[…]
First of all, all the in-lined JavaScript code should be moved to the place, where it should be – .js files on the classpath that can be tested (and mocked), and recognized by IDEs, which make them more comfortable to edit (because oh highlights, JavaDocs, autocompletion and other features we love our IDEs for).
via: http://vasilrem.com/blog/software-development/stored-javascript-in-mongo/