As expected, it is impossible (as in MongoDB 2.2) to access another database from the Map / Reduce functions. In addition to the potential impact on performance, there is also the possibility of creating deadlocks and other unwanted side effects.
Unfortunately, this leaves print()mongo in the log as the only out-of-range output option.
Depending on your diagnostic output, one way you could try would be the following:
, M/R:
var diag = {
'run' : diagrun,
'phase': 'map',
'key' : z
}
print("MAPDIAG:" + tojson(diag));
:
$ tail -f mongo.log | grep "^MAPDIAG"
MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "dog" }
MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "cat" }
MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "cat" }
MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "mouse" }
MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "cat" }
MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "dog" }
MAPDIAG:{ "run" : "20120824", "phase" : "reduce", "key" : "cat", "total" : 3 }
MAPDIAG:{ "run" : "20120824", "phase" : "reduce", "key" : "dog", "total" : 2 }