Grégori Machado Grégori Machado - 6 months ago 55
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


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