Search code examples
pythongoogle-cloud-firestoreaggregate-functionsfirebase-admin

Firestore Python SDK - count() aggregation


I'm using Firebase Firestore in my Python project (with their official Python SDK) and having trouble performing count() aggregation. This funciton is supported according to their docs. However, they do not provide Python example ( they do in other parts of documentation ). I tried to play with it in Python console, tried something like this:

query = db.collection('videos').where('status', '==', 'pending')
query.count()

without any luck. So I'm wondering how is it possible to implement? Does Python SDK support this functionality?


Solution

  • Update:

    count() query is now available in Firebase Admin SDK from version 6.1.0.


    Firebase Admin Python SDK doesn't support that query yet. You can still use the runAggregationQuery REST API meanwhile. The Google Cloud Firestore Python SDK has Aggregation result types available from v2.7.0+ so it should be available in Admin SDK soon.