【问题标题】:Firestore: List subcollections of a document using pythonFirestore:使用 python 列出文档的子集合
【发布时间】:2020-09-23 23:33:37
【问题描述】:

是否可以使用 python 列出文档的子集合? 谷歌文档似乎不一致

这里他们说 Python 客户端库中没有 get collections 方法:

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

这里他们说 class collections() 列出子集合:

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

所以我尝试了类似的方法:

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

但它不起作用。

【问题讨论】:

标签: python firebase google-cloud-firestore


【解决方案1】:

你是对的。文档中缺少此内容:

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)

【讨论】:

  • 谢谢胡安!我们可以假设这也将很快在文档中得到解决吗? ;-)
  • 我们正在努力 :-)
猜你喜欢
  • 2018-10-09
  • 2021-12-16
  • 2018-03-17
  • 2018-10-21
  • 2020-08-25
  • 2020-07-26
相关资源
最近更新 更多