Getting unwanted output from MongoDB collation Getting unwanted output from MongoDB collation mongodb mongodb

Getting unwanted output from MongoDB collation


Found the issue

I debugged the issue found that the collation uses the normalization for encoding the query response. And by default, that value is false. So, the shell query was returning the correct output.

But In Mongo-java-Driver it was setting normalization as true(by default).

Updated the builder with normalization as false for same:

Collation collation = Collation.builder().locale("en").numericOrdering(true).normalization(false).build();
ArrayList<Document> response = new ArrayList<>();ArrayList<Bson> aggregate = new ArrayList<Bson>(Arrays.asList(  match(gt("version", "1.9.4")), sort(descending("version")),  project(fields(include("version"), exclude("_id")))));this.database.getCollection(sysversion).aggregate(aggregate).collation(collation).into(response);

This fixed my issue.