1

I am trying to sort my result with the case insensitive option. So here is my code:

List<AggregationOperation> operations = new ArrayList<>();   
Sort.Order sort = ....ignoreCase();
operations.add(new SortOperation(new Sort(sort)));

But when I execute my query using an aggregation, it doesn't work:

mongoOperations.aggregate(Aggregation.newAggregation(operations).withOptions(aggregationOptions)

I displayed the query in the debug console and the ignoreCase totally disappeared in the aggregation:

db.getCollection('persons').aggregate([   
    {  
      "$sort":{  
        "buyer.organization.name":-1
      }
    }
])

How can I put the ignore case option in my aggregation?

Thanks for your help!

Anna
  • 839
  • 2
  • 17
  • 33

2 Answers2

1

The solution for this was using MongoDB Collation and add it in the mongoOperations. I used strength = 1 which ignores cases.

Anna
  • 839
  • 2
  • 17
  • 33
0

This is how I solved my sorting issue

val res =
          mongoTemplate.aggregate(
              aggregations.withOptions(
                  new AggregationOptions(
                      false,
                      false,
                      null,
                      Collation.of("en").strength(Collation.ComparisonLevel.primary()))),
              Path.class,
              CountedAggregationFolderContentDTO.class);
Rodolfo Velasco
  • 845
  • 2
  • 12
  • 27