0

The problem I can't seem to find a straight answer to is how can I do a query on this list in the Firebase database by some field (a username in my case) to find the associated key for that user given that username is guaranteed to be a unique value.

I've read through the documentation on queries, but it looks like all of them need a key in some shape or form is that really the case? And if it is how is this normally avoided?

Thanks a million below is how my DB is designed.

Right now, in my database there is a list of user objects:

Database
    -users
        -{SomeUniqueKey}
            -data: "some data"
            -username: "user1"
            -usernameThisUserIsFollowing: "user2"
        +{SomeOtherUniqueKey}
AL.
  • 36,815
  • 10
  • 142
  • 281
dschon
  • 3
  • 2
  • [This post](http://stackoverflow.com/a/26701282/4625829) might be of some help. – AL. May 02 '17 at 02:10
  • [Ensuring uniqueness has been covered quite a few times already](http://stackoverflow.com/questions/35243492/firebase-android-make-username-unique). The answers given there were authoritative: the best way to guarantee uniqueness is to [keep the values in keys under a given location](http://stackoverflow.com/questions/35243492/firebase-android-make-username-unique), since keys under a location are unique by nature. See http://stackoverflow.com/questions/35243492/firebase-android-make-username-unique – Frank van Puffelen May 02 '17 at 02:56
  • These comments answer my specific case so thank you for solving my problem but for future reference: It isn't possible to do a where like query? Asking for all of the objects regardless of the key where one of the subfields is equal to a certain value? I know this isn't as designed as well in this case but something like give me all users where username = bob – dschon May 04 '17 at 15:21

1 Answers1

1

You may use equalTo.

Reference: https://firebase.google.com/docs/database/

Mohammad Sajjad
  • 35
  • 1
  • 13