I had a quick look at this. Unfortunately I couldn't reproduce your problem. Which Version of Spring Data MongoDB are you using? You are refering to a rather old version of Spring Data MongoDB the current version is 1.4.1: http://docs.spring.io/spring-data/data-mongo/docs/1.4.1.RELEASE/reference/html/mongo.core.html#mongo.mapreduce
The M/R code for the pure MongoDriver and Spring Data MongoDb doesn't seem to match, e.g. you are not using the finalizeFunction. Would you mind writing a test case that reproduces the issue?
You can use the MapReduceTests for that: https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapreduce/MapReduceTests.java#L58
This is what I tried:
@Test
public void shoudSupportRunningCompressedJavaScriptAsMapReduceCommands() {
createMapReduceData();
MapReduceResults<ValueObject> results = mongoTemplate.mapReduce(
"jmr1",
mapFunction,
reduceFunction,
new MapReduceOptions().outputCollection("map_reduce_java_test").outputTypeReplace()
.finalizeFunction("function(key,reducedValue){return reducedValue}"), ValueObject.class);
assertThat(results, is(notNullValue()));
Map<String, Float> m = copyToMap(results);
assertEquals(1, m.get("a").intValue());
assertEquals(2, m.get("b").intValue());
assertEquals(2, m.get("c").intValue());
assertEquals(1, m.get("d").intValue());
}