1

hi guys is there a way to count the amount children in firebase?

i have a database structure like this

Testitem1{
test: ""
},
Testitem2{
test: ""
}

i want to count only the Testitem nodes

markharrop
  • 866
  • 1
  • 9
  • 30

1 Answers1

2

To count child nodes in firebase real-time database.

FirebaseDatabase database = FirebaseDatabase.getInstance(); // get the reference of child containing testitems
DatabaseReference myRef = database.getReference();

myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    for (DataSnapshot snap: dataSnapshot.getChildren()) {
        Log.e(snap.getKey(),snap.getChildrenCount() + "");
    }
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
Lekr0
  • 653
  • 1
  • 8
  • 17