How to retrieve objects from firebase by key value

前端 未结 2 1197
有刺的猬
有刺的猬 2020-12-15 15:06

I\'m new to firebase and I have such structure of my firebase project

I want to get all objects, that \"Interested\" value is equal to \"men\"

I wr

2条回答
  •  有刺的猬
    2020-12-15 15:36

    you need to loop through all the key-value profiles

          if let allProfiles = snapshot.value as? [String:AnyObject] {
                for (_,profile) in allProfiles {
                      print(profile);
                      let userInterest = profile["Interest"]
               }
           }
    

    Here _ is the key that is in the format KYXA-random string and profile will be the element for that key.

    Edit:

    There is querying for child values as per the docs.

    Try thisUserRef.queryOrderedByChild("Interest").equalTo("men") and then using the inner loop that i specified in the answer

提交回复
热议问题