How to use startAt(double value, String key) and endAt(double value, String key) Firebase RealTime Database in Android

前端 未结 1 826
不知归路
不知归路 2021-01-16 14:02

I want to do a query by using orderByChild and also filtering with the key of those child. In this case, my keys and values are both data that works for queryin

相关标签:
1条回答
  • 2021-01-16 14:25

    You seem to think that passing two arguments to endAt() makes the query end at whichever of the value or key comes first. That is not how queries work in Firebase.

    The second argument to endAt() is only used after the query finds nodes that match the first argument.

    So when you're passing endAt(500, "200xyz"), the database first filters on nodes with value2 equal to value2 (the first argument). This means it finds this node as the end of the query:

    "500xyz":{
      "value1": 500,
      "value2": 500,
      "name":"500xyz"
    }
    

    It then uses the key 200xyz (the second argument) to determine whether to include this node or not (technically: where in the list of multiple nodes to end returning). Since the key 200xyz is before 500xyz the query result doesn't include this node, resulting in:

    "100xyz":{
      "value1": 100,
      "value2": 100,
      "name":"100xyz"
    },
    "200xyz":{
      "value1": 200,
      "value2": 200,
      "name":"200xyz"
    },
    "300xyz":{
      "value1": 300,
      "value2": 300,
      "name":"300xyz"
    },
    "400xyz":{
      "value1": 400,
      "value2": 400,
      "name":"400xyz"
    },
    

    Also see:

    • Firebase orderByChild with startAt()'s second argument w/ pagination not odering:
    • Limiting the firebase equalTo query with the optional key parameter
    • Firebase Query order by and start at name
    • How to paging query from Firebase using Android FirebaseUI
    0 讨论(0)
提交回复
热议问题