How To Retrieve Count Of Child Under Root Node In Firebase
prev.child('ViewLikes').child(postId).push().setValue('viewed'); How to count the number of childs under the the root(9999999977). I'm using Value event listener but still the I
Solution 1:
To get the number of childrens within the 9999999977
node, please use the following code:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference ref = rootRef.child("ViewLikes").child("9999999977");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long count = dataSnapshot.getChildrenCount();
Log.d("TAG", "count= " + count);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
ref.addListenerForSingleValueEvent(valueEventListener);
The out will be: count= 7
Post a Comment for "How To Retrieve Count Of Child Under Root Node In Firebase"