Firestore: List subcollections of a document using python

ぐ巨炮叔叔 提交于 2020-06-17 22:52:51

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/62203845/firestore-list-subcollections-of-a-document-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!