简体   繁体   English

Python 在 Firebase Firestore 中列出带有子文档的 ID

[英]Python list id with subdocuments in Firebase Firestore

try:
    self.groupList = self.db.collection(u'kholles').stream()
    self.groupList = [str(group.id) for group in self.groupList]
    return self.groupList
except:
    return []

I have a problem, I want to retrieve all documents id from the second row: [A11, A12, ..., E22] but I have to use subdocument and this doesn't seem to work (I think it's because documents values aren't data but collections).我有一个问题,我想从第二行检索所有文档 ID:[A11, A12, ..., E22] 但我必须使用子文档,这似乎不起作用(我认为这是因为文档值是'不是数据而是集合)。

This code returns an empty array [] instead of returning [A11, A12, ..., E22].此代码返回一个空数组 [] 而不是返回 [A11, A12, ..., E22]。

这是我的 Firebase 架构

The documents A 11 , A 12 , A 13 etc do not exist and will therefore not show in your query.文档A 11A 12A 13等不存在,因此不会显示在您的查询中。

Let me try to explain what is happening here.让我试着解释一下这里发生了什么。 You created 4 documents under this collection knolles/A 11/liste .您在此集合knolles/A 11/liste下创建了 4 个文档。 So A 11 is not a document.所以A 11不是文档。 It was never created.它从未被创建。 Rather the path knolles/A 11/liste contains some documents.相反,路径knolles/A 11/liste包含一些文件。

This happens because in Cloud Firestore it is possible to create documents under any path and that path can be virtual.发生这种情况是因为在 Cloud Firestore 中,可以在任何路径下创建文档,并且该路径可以是虚拟的。 In other words, documents can be created under any path regardless of if documents or collections exist in that path.换句话说,可以在任何路径下创建文档,而不管该路径下是否存在文档或collections。

If you want them to show in your query, you can create documents under the knolles/A 11 path.如果您希望它们显示在您的查询中,您可以在knolles/A 11路径下创建文档。

But for me personally, when I am in this situation, I usually know the full path to my collections (eg knolls/A 11/liste ) and so I just fetch them directly.但就我个人而言,当我处于这种情况时,我通常知道我的 collections 的完整路径(例如knolls/A 11/liste ),所以我直接获取它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM