Sorting special characters with collation

Hello All,

I have a collection with a field named “name”. The documents in my collection have the following names: “test.1”, “test@1”, and “test_1”.

I am using the following query:

javascriptdb.collection.find(mongo_filter)
    .collation({locale: "fr"})
    .sort({name: 1});

The output I receive is:

json[
    {"name": "test_1"},
    {"name": "test.1"},
    {"name": "test@1"}
]

However, I expected the output to be:

json[
    {"name": "test.1"},
    {"name": "test@1"},
    {"name": "test_1"}
]

I applied collation to make the sort case-insensitive.

I am confused about the order of special characters. It seems that “_” comes before all other special characters, while according to ASCII order, it should come after “.” and “@”.

I suspect this behavior is linked to the locale used. I also tested with JavaScript’s localCompare, which gives me the expected result.

Could someone help me understand how collation works in this case or let me know if I’m doing something wrong?

Thank you!

Hello ,

Any update or help on this subject ?