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 querying what I want.
My problem is presented when the keys contains numbers, if the keys only have letters, then there is no problem. I'm trying to maintain always letters along the numbers since I read the recommendation in another answer directly from a firebaser.
My json is:
{
"my_list":{
"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"
},
"500xyz":{
"value1": 500,
"value2": 500,
"name":"500xyz"
}
}
}
My code is:
DatabaseReference root = FirebaseDatabase.getInstance().getReference().getRoot();
DatabaseReference list = root.child("my_list");
list.orderByChild("value2").startAt(100, "100xyz").endAt(500, "200xyz").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
SomeModel someModel = dataSnapshot.getValue(SomeModel.class);
Log.d("SOME_MODEL", someModel.getName());
}
});
The problem is I can see 4 childs in the console:
D/SOME_MODEL: 100xyz
D/SOME_MODEL: 200xyz
D/SOME_MODEL: 300xyz
D/SOME_MODEL: 400xyz
But I should only be seen 2
D/SOME_MODEL: 100xyz
D/SOME_MODEL: 200xyz
I want to emphazise: it does works, as long as the keys don't have numbers.
How can I filter by orderByChild and key at the same time when the keys have numbers?