How to retrieve objects from firebase by key value

前端 未结 2 1207
有刺的猬
有刺的猬 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:14

    This is a basic query in Firebase. (Updated for Swift 3, Firebase 4)

        let profileRef = self.ref.child("profile")
        profileRef.queryOrdered(byChild: "Interest").queryEqual(toValue: "men")
        profileRef.observeSingleEvent(of: .value, with: { snapshot in
    
            for child in snapshot.children {
                let dict = child as! [String: Any]
                let name = dict["Name"] as! String
                print(name)
            }
        })
    

    The legacy documentation from Firebase really outlines how to work with queries: find it here

    Legacy Firebase Queries

    The new documentation is pretty thin.

    Oh, just to point out the variable; thisUserNode should probably be profileRef as that's what you are actually query'ing.

提交回复
热议问题