0

I am trying to make search field in my app, I am using startAt and endAt methods. These methods work very well without case sensitivity. But, unfortunately it doesn't work properly with incase sensitivity.

   let startText = searchText.toUpperCase();
   let endText = searchText.toLowerCase()
  
   const productRef=db
      .collection("products")
      .orderBy(searchField)
      .startAt(startText).endAt(endText+"\uf8ff");

Assume I have ["a", "A", "AB", "ABC", "Z", "a"] If I search "AB" it only sorts the data only, it retrieves "AB", "ABC", "Z", "a" Or if I search "z" it retrieves "Z", "a", "z"

Am I doing something wrong or this method actually doesn't work?

I have seen people keeping lowercase versions of fields in the document, is this the only way of solving the problem?

name:"Overflow" nameLower:"overflow"

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • The Firebase Realtime Database and Cloud Firestore are two separate databases. Please only mark your question with the relevant tag, not with both. – Frank van Puffelen Jan 26 '21 at 15:22
  • Searches in Firestore are case sensitive. What you found is the idiomatic workaround. See https://stackoverflow.com/questions/48096063/cloud-firestore-case-insensitive-sorting-using-query – Frank van Puffelen Jan 26 '21 at 15:23

0 Answers0