As Gates vice president said, you need to add cache to the global area. So, to provide a complete answer, given your script, this is what you will need to do:
db.runCommand( { mapreduce : <your collection>, map : <your map function, or reference to it>, reduce : <your reduce function, or reference to it>, scope : { cache : {} } } );
The command will inject the contents of the "scope" object parameter into your global context. Then caching will work the way you use it in your map function. I tested this.
Pawel veselov
source share