I tried to read sorted data from Cloud Firestore using OrderBy. And Firestore returned data as Following Order:
AAA
BBB
aaa
bbb
Now, what I want is something like following:
AAA
aaa
BBB
bbb
I want this result only using OrderBy not by manual Sorting.
Is there any way to sort like this in Firestore?
Please provide me a solution for this.
Thanks in Advance.
You could also do it manually after you get your results:
Sorting in Cloud Firestore is case sensitive. There is no flag to make the sorting ignore the case.
The only way to achieve your use-case is to store the field twice.
Let's say your field that stores 'AAA' & 'aaa' is called
myData
. In your client code you'll need to store a second field calledmyData_insensitive
where you store a case-insensitive copy of the data.Now you can query and/or order by
myData_insensitive
, but displaymyData
.Two interesting thing about this area is:
Without creating separate indexes for each collation to solve (2), one implementation approach to deal with (1) is via case folding. If you want to only support modern browser versions, then the following gives you a JavaScript example:
This will give you a document in Cloud Firestore with the following fields:
To handle older browser, you can see one solution in How do I make toLowerCase() and toUpperCase() consistent across browsers