Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore: List subcollections of a document using python

Is it possible list subcollections of a document using python? It seems that google documentation is discordant

Here they say that get collections method is not available in the Python client library:

https://firebase.google.com/docs/firestore/query-data/get-data#python_6

Here they say that class collections() list subcollections:

https://googleapis.dev/python/firestore/latest/document.html

So I try something like:

collnameref = db.collection(collname)
docs = collnameref.stream()
for doc in docs:
    print (doc.collections())

but it doesn't work.

like image 534
franco_b Avatar asked Apr 16 '26 06:04

franco_b


1 Answers

You're right. This is missing from the documentation:

collnameref = db.collection(collname)
docs = collnameref.stream()
for doc in docs:
    # List subcollections in each doc
    for collection_ref in doc.reference.collections():
        print(collection_ref.parent.path + collection_ref.id)
like image 141
Juan Lara Avatar answered Apr 17 '26 19:04

Juan Lara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!