Error in alphabetical order MongoDB

I use the standard $$$ sort operation and find that the result is broken if there is a lowercase uppercase string.

Example:

Google HTC LG Yoc iTaxi 

As you can see, iTaxi gets iTaxi to the bottom, instead of being located after HTC .

+4
source share
1 answer

This is case sensitive sorting where lowercase letters come after uppercase letters. Thus, for sorting and searching, it makes sense to store a "normalized field", where all lines are headers, and some special characters are deleted or replaced, for example.

 [ { name : "iTaxi", searchName: "ITAXI" }, { name : "HTC", searchName: "HTC" }, { name : "Ümlaut", searchName: "UMLAUT" }, .... ] 

In this example, the searchName field should be indexed, not the name field.

Normalizing strings, especially replacing umlauts and special characters, is a bit complicated. For example, German ü should become ue , and ß should become ss or sz , but that goes far beyond the scope of your original question.

+6
source

Source: https://habr.com/ru/post/1469320/


All Articles