Skip to content Skip to sidebar Skip to footer

How To Count The Number Of Documents Firestore On Flutter?

I want to calculate how many documents are in a collection, not the length of the document. I have tried it with some code but what appears is the length of the character from my d

Solution 1:

An Example Function to fetch Documents Count.

void countDocuments() async {
    QuerySnapshot _myDoc = await Firestore.instance.collection('product').getDocuments();
    List<DocumentSnapshot> _myDocCount = _myDoc.documents;
    print(_myDocCount.length);  // Count of Documents in Collection
}

Post a Comment for "How To Count The Number Of Documents Firestore On Flutter?"