Android Firebase Query

2020-07-09 08:24发布

问题:

I have this structure Now, Im making a query like this:

 DatabaseReference myRef = database.getReference("users");
        myRef.equalTo("6991580","ci").addListenerForSingleValueEvent(new ...

I was expecting the second node as result.. Then I get:

DataSnapshot { key = users, value = null }

So, what is wrong with this query? or maybe Im doing something wrong?

Best regards and thanks for reply.

回答1:

You need to tell Firebase what child property you want to order/filter on:

myRef.orderByChild("ci").equalTo("6991580").addListenerForSingleValueEvent(...

The other format of ordering is a commonly misunderstood version. I'd recommend simply staying away from it.



回答2:

I had the same problem and solve it by changing listener:

myRef.orderByChild("ci").equalTo("6991580").addChildEventListener(new ChildEventListener() {}