Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Firebase Query

I have this structure enter image description here 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.

like image 921
Vinicius DSL Avatar asked Jun 01 '16 22:06

Vinicius DSL


People also ask

How do I get particular data from Firebase?

Firebase data is retrieved by either a one time call to GetValueAsync() or attaching to an event on a FirebaseDatabase reference. The event listener is called once for the initial state of the data and again anytime the data changes.

What is a query in firestore?

Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group. These queries can also be used with either get() or addSnapshotListener() , as described in Get Data and Get Realtime Updates.

What is addListenerForSingleValueEvent?

addValueEventListener() keep listening to query or database reference it is attached to. But addListenerForSingleValueEvent() executes onDataChange method immediately and after executing that method once, it stops listening to the reference location it is attached to. Follow this answer to receive notifications.

Can you search Firebase?

To enable full text search of your Cloud Firestore data, use a dedicated third-party search service. These services provide advanced indexing and search capabilities far beyond what any simple database query can offer. Before continuing, research then choose one of the search providers below: Elastic.


2 Answers

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.

like image 61
Frank van Puffelen Avatar answered Oct 20 '22 09:10

Frank van Puffelen


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

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

like image 43
Renat Kravchenko Avatar answered Oct 20 '22 09:10

Renat Kravchenko