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
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
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) {
}
});