How i can get number of documents from firebase realtime database? I find answers only for firebase firestore.
Asked
Active
Viewed 96 times
0
-
1its answer to firestore collection, i need realtime db – Ancorp Team Sep 10 '19 at 12:30
-
You can search for a combination of tags, so: https://stackoverflow.com/search?q=%5Bfirebase-realtime-database%5D%5Bjavascript%5D+count+number+of+children – Frank van Puffelen Sep 10 '19 at 13:08
1 Answers
0
If you want to get the number of your children in a Firebase Realtime Database, you have to use getChildrenCount()
on a DataSnapshot
object. I would recommend to read in the Firebase Docs for more information.
Here is also an example on how to use it.
The following Code example is also from the Firebase Docs. It's a bit modified.
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference();
// Attach a listener to print out the number of total children
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long count = dataSnapshot.getChildrenCount();
System.out.println(count);
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});

Constantin Beer
- 5,447
- 6
- 25
- 43