Firebase snapshot.key not returning actual key?

前端 未结 1 1426
萌比男神i
萌比男神i 2020-12-01 22:35

I have a query that searches for a user based on user ID.

usersRef.queryOrderedByChild(\"email\").queryEqualToValue(email).observeEventType(.Value, withBloc         


        
1条回答
  •  一整个雨季
    2020-12-01 23:34

    When you run a query at a location, the result will be a list of the matching children. Even if there is only a single matching item, the result will be a list of one child.

    You're printing the key of all resulting children. Since there is no single result, the SDK prints the key of the location/collection that you queried: users.

    What you're likely looking for is to loop over the matching children and print their keys:

    let query = usersRef.queryOrderedByChild("email").queryEqualToValue(email)
    query.observeEventType(.Value, withBlock: { snapshot in
        for child in snapshot.children {
            print(child.key)
        }
    })
    

    0 讨论(0)
提交回复
热议问题