Firebase queryEqualToValue with childKey

前端 未结 1 1301
南旧
南旧 2020-12-07 02:19

I am trying to query data in my Firebase database using:

queryEqual(toValue: Any?, childKey: String?)

My database structure:



        
相关标签:
1条回答
  • 2020-12-07 02:59

    The two-parameter queryEqualToValue:childKey: (and its brethren queryStartingAtValue:childKey: and queryEndingAtValue:childKey:) are unfortunately some of the most misunderstood methods in the Firebase Database API.

    To order by a child and then filter on a value of that child, you have to call queryOrderedByChild().queryEqualToValue(). So as @ElCaptainV2.0 said:

    databaseReference.child("Schools")
        .queryOrderedByChild("scho‌​olNameLC")
        .queryEqua‌​lToValue("test school 1")
    

    You only should use the childKey: parameter if you also want to start at a specific key in all nodes that have the same matching test school 1 value. This overload is really mostly useful when you're trying to paginate/endless scroll results.

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