Diaz diaz
Diaz diaz

Reputation: 284

Firebase query like WHERE clause of sql

I am working with Firebase in Android. In my app, there is a scenario where I need to fetch the filtered list from root node on basis of a field which is inside its child. For more clearance on problem see the sample database structure below.

enter image description here

For example, I need to fetch from Root Chats where part contains 3 as value. I have tried Firebase Query but not helpful. Is there a way to get the filtered list as above?

Upvotes: 0

Views: 1155

Answers (2)

Alex Mamo
Alex Mamo

Reputation: 138824

You cannot query your database as mentioned in your question using the actual database structure. In such cases, there is a practice named denormalization and for that I recomend you see this video, Denormalization is normal with the Firebase Database.

In your case, you need to get the part node out from chat node and create a new top level node in which you can store those values. I recomend you also use as the name of the child, the exact name that you want to query. In this case you will be able to attach a listener on that particular node and use exists() method to check a child for existens.

In also recomend you read this post, Structuring your Firebase Data correctly for a Complex App for a better understanding.

There are two more resourses that I want to share, The Firebase Database For SQL Developers and NoSQL Data Modeling Techniques.

Upvotes: 2

Yıldırım
Yıldırım

Reputation: 787

 Query query = databaseReference.orderByChild("databaseData").equalTo("yourdatayouwant");

You can do that with this way

Upvotes: 0

Related Questions