1

In flutter we use the Querysnapshot.documents.length to fetch number of documents?

Similarly , How can we can do it in Java Android Studio

Thanks in advance

Shivam
  • 13
  • 2

2 Answers2

2

Instead of looping just get size

db.collection("Store")
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
               Log.d(TAG, "Size is", task.getResult().size());
            } else {
                Log.d(TAG, "Error getting documents: ", task.getException());
            }
        }
    });
Ashish
  • 6,791
  • 3
  • 26
  • 48
1

Already Answered Here

No built in Method Actually, We have to count the documents using for loop

Inder Pal Singh
  • 380
  • 4
  • 16