1

I have a firebase application and I want to be able to search for user but the problem I am having is if the database value is hello, if user inputs hello in the search bar it returns true but if Hello, it returns false. I want to be able to treat lowercase and uppercase as the same so even if a user typed hElLo, it returns true. below is my code.

func fsFindUser(q user: String, completion: @escaping CompletionHandler) {

        let userRef = fsRef.collection(USERS_REF)
        let query = userRef.whereField("user", isEqualTo: user)

        query.addSnapshotListener { (snapshot, error) in

            if let error = error {
                print("Error getting document: \(error)")
            } else if (snapshot?.isEmpty)! {

                completion(false)

            } else {
                completion(true)

            }
        }
    }
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
King
  • 1,885
  • 3
  • 27
  • 84

1 Answers1

3

The answer is you store two sets of data in your node; one used for queries that's lowercased and the other used for display

users
  uid_0
    queryable: "mcdonald"
    display: "McDonald"
  uid_1
    queryable: "van winkle"
    display: "Van Winkle"
Jay
  • 34,438
  • 18
  • 52
  • 81