In the Java code I'm working on, I have set up a map reduce operation using MongoDB template.
String reduceFunction="classpath:reduceJustCount.js";
String mapFunction = "classpath:mapBreachesByModule.js";
MapReduceResults<MapReduceValue> mapReduceResults = mongoTemplate.mapReduce(query, Collections.MONGO_COLLECTION, mapFunction, reduceFunction, MapReduceValue.class);
The JavaScript function for mapping breaches by module is included below.
function () {
emit(this.ModuleName, this.Breach);
}
The reduce function used just counts the number of values.
function (key, values){
return values.length;
}
I have one specific row in my Collection that looks like this:
{ "_id" : { "$oid" : "52efc24bc09559e531269e2c"} , "ModuleName" : "SystemParameterServiceRS" , "Breach" : false }
However, when running the code, I encounter an exception related to converting Boolean to integer.
nested exception is org.springframework.c
ore.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.Boolean to type int] with root cause
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.Boolean to type int
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:475)
.... (remaining stack trace omitted for brevity) ...
Although I am aware that the field being mapped is boolean and should be totaled, even simplifying the reduce function does not resolve the issue.
If anyone has any insights or solutions, your help would be greatly appreciated. Thank you!