Check if username is available using firebase

Hi
I am quite new and most I learned is from the tutorial videos, which are great.
I am trying to build an app, using Firebase as database.
In a simple app when a user signs up with the " Auth.auth().createUser(withEmail: email, password: password) ", what happens is if username is available, an account is created, as expected.
In the photo app tutorial, where the login is done with the firebase UI, you either get logged in, or are redirected to creating a username.
If you however want your own design, and you want to check if an username is available is there an more simple way than what I found on “stackoverflow”:

func checkUsernameAvailability(completion: @escaping (_ available:Bool)->()){
    guard let lowercasedText = usernameTextField.text?.lowercased() else {completion(false); return}
    let ref = Database.database().reference().child("users").child("username").child(lowercasedText)
    ref.observeSingleEvent(of: .value) { (snapshot) in
        if snapshot.exists(){
            completion(false)
            return
        }else{
            completion(true)
        }
    }
}

I have 3 different kinds of users, so I guess by implementing the code above, I would have to check all 3 collections, to be sure that the username is available?

I guess I can pass the collection path as a parameter, so I only have to run the method 3 times, instead of copying all of it 3 times?

regards
Thomas