Grégori Machado Grégori Machado - 1 year ago 107
Android Question

Search for a specific value in all children in a list in Firebase

I have the following database on Firebase:
firebase database

I want to return a search on users if there is any with the true type.

mDatabaseReference.child("users").addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild("type")) {//I need the verification here.
} else {

public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "getUser:onCancelled", databaseError.toException());

Thank you in advance for your attention

Answer Source

What you are looking for is a filtered query like this:

Query filterQuery = databaseReference.orderByChild("type").equalTo(true);

You can also have a look at this answer for more examples about filtering data and have a look at these docs.

Do let me know if this points you in right direction.


You can check for null by putting this condition in a if statement in onDataChange

dataSnapshot.getValue() != null
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download