When using MongoDB map reduce, you may encounter the error message: "Unable to find a converter that can convert from type java.lang.Boolean to type int."

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!

Answer №1

It is clear that the issue lies in the types being used and processed in your map and reduce phases. Check out these two links which are similar to the example you provided:

MapReduce using MongoDB Java Driver fails with wrong type for BSONElement assertion

Furthermore, if you're not set on using MapReduce, consider exploring the Aggregation pipeline. This can often achieve faster results compared to using MapReduce.

For additional Java resources: http://docs.mongodb.org/ecosystem/tutorial/use-aggregation-framework-with-java-driver/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating jQuery objects with concise code

I'm in the process of integrating caching and minimizing DOM manipulation in my highly intricate JS code. I am keen to ensure efficiency, so I'm wondering which approach is more optimized? 1) var $thebox = $(".textbox[data-title*='"+dt+"&a ...

Loop through the HTML and print it repeatedly

I've been using this code to retrieve Json data and display it based on the same id. However, I've noticed that it only prints once and doesn't display all the data as expected. var requiredData; $.getJSON('http://127.0.0.1/appcpanel/ ...

What steps do I need to take in order to create functions that are

I have 10 functions with similar structures: function socialMedia_ajax(media){ return ajaxRequest('search/' + media + 'id', media + 'id').then( function(res) { var imgStatus = res[1].length > 0 ? "c ...

My messages are falling on deaf ears as the Discord bot remains unresponsive (js)

After creating a Discord bot using node.js and VS Code, I am encountering an issue where the bot appears online but does not respond to messages. Despite ensuring that the bot has all the necessary permissions, I cannot identify the root cause of this prob ...

Limiting jQuery searches to a specific region: Tips and tricks

If I have the code snippet below: <div class="foo"> <div> some text <div class="bar"> </div> </div> </div> <div class="foo"> <div> some text <div class="bar"> some text </div> </div> </ ...

Increase the resolution of images with this Java library

Currently, I am in search of a Java library that can be integrated into my project to enhance the resolution of an existing image. Specifically, I am dealing with Android Bitmap objects. I do not expect anything as extreme as CSI-like enhancements, but rat ...

What is causing the duplication of leaves when using this DFS implementation?

I created an algorithm to compare if two trees have the same leaves. https://i.sstatic.net/lpO2C.png Both trees display matching leaf numbers in the exact order, resulting in a true outcome. Below is the code that I formulated: function leafSimilar(root ...

Arranging Items in a JavaScript Array based on a Specific Attribute

I have devised a somewhat rudimentary method to achieve this task, but I thought it would be better to seek advice from the numerous experts here at SO. Essentially, I possess an array structured like the one below: var bugs = [ { id: "197526" ...

Is there a way to retrieve the response body in Express framework?

In my NodeJS API using Express, I am attempting to save the response body of a request. To achieve this, I have created two middleware functions. app.use((req, res,next) => { res.status(404).json({ errors: [{ field: "url", ...

Updating the value of a MongoDB item two days after its creation

I've been working on a NodeJS application that stores form data in a MongoDB database collection. My goal is to implement a function that can modify certain values of the object in the database collection 48 hours after the form data is initially save ...

Is it possible to automate a React JS website using the Robot Framework?

I wanted to explore if I could use the robot framework for automating testing on my react js single page application. ...

Error in Discord.JS: The function message.author.hasPermission is not recognized

As I was working on creating a new command for my discord.js bot to toggle commands on/off, I ran into some issues. Specifically, when I attempted to use the .hasPermission function, I encountered the following error message: TypeError: message.author.ha ...

Dynamic JSX tag including attributes

In my project, I have a set of components stored in a folder named systemStatus. These components are accessible through an index.js file as follows: export UserCount from './UserCount' Additionally, I have a JSX component called Status which i ...

Using the jqLite .html() method directly as a watch listener in AngularJS

I'm attempting to use the jqLite function element.html directly as a listener for a watcher: angular.module('testApp', []).directive('test', function () { return { restrict: 'A', link: function (scope, element, ...

execute task to optimize CSS encoding in the build process

Creating a static project with yeoman -webapp I've implemented a UTF checkmark in my .scss files: [type="checkbox"]:checked + label:after { content: '✔'; position: absolute; top: 3px; left: 0px; font-size: 22px; color:$color-pr ...

Guidelines on changing the value of a nested field with a dynamic name within the MongoDB aggregation pipeline

When working with MongoDB aggregation, I encounter the challenge of updating a nested field whose name is determined by another field in the document. Let's consider an example document: { "prop": { "nestedField": "oldVa ...

Custom date formatting with jQuery table sorting

I have been using a jQuery plugin called Tablesorter to sort a table. I am facing an issue with sorting dates in the yyyy MMM dd format, especially because my date inputs are in French. Here is an example of how the dates are formatted: 2014 janv. 05 20 ...

Divide the string into separate JSON and non-JSON components

Here is a string I have: const str = '{ "foo": { "bar": { "baz": 5 } } } Some additional text'; Is there a reliable method in JavaScript to separate the JSON part from the non-JSON part of this string? The string always starts with valid JSON, ...

What is the best way to run a block of code sequentially across multiple threads?

Each of my threads contains the following statement: ((JavascriptExecutor) driver).executeScript("window.print();"); I need to ensure that this statement is executed one at a time in each thread, as the desired output is not achieved when multiple thread ...

Tips for mocking a particular http resource (URL) solely in Angular

I'm part of a team with front-end and back-end developers. At times, the front-end team needs to make REST requests to an http address or REST-resource that hasn't been implemented yet. Within ngMockE2E, I've come across the $httpBackend se ...