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
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: