1
votes

I have the following structure in my firebase database.

  "friendRequest" : {
      "uid" : { 
          "-KUT7mxTW7WGLkgrZVM4" : {
              "fromUid" : "uid"
          }
      }
  }

In my iOS app, a user can make a friend request, similar in principle to adding friends on Facebook.

I need to access the fromUid property but I don't know the parent key above it which is generated by childByAutoId() (the third line - "-KUT7mxTW7WGLkgrZVM4").

How can I access the fromUid key to get its value?

1

1 Answers

0
votes

I think you're looking for something like:

ref.child("friendRequest")
   .child(FIRAuth.auth()?.currentUser.uid)
   .queryOrdered(byChild: "fromId")
   .queryEqual(toValue: "theUidThatYou'reLookingFor")
   .observeSingleEvent(of: .childAdded, with: { (snapshot) in
        print("\(snapshot.key)")
    })