Home > Enterprise >  Python list id with subdocuments in Firebase Firestore
Python list id with subdocuments in Firebase Firestore

Time:04-11

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).

This code returns an empty array [] instead of returning [A11, A12, ..., E22].

Here is my firebase architecture

CodePudding user response:

The documents A 11, A 12, A 13 etc do not exist and will therefore not show in your query.

Let me try to explain what is happening here. You created 4 documents under this collection knolles/A 11/liste. So A 11 is not a document. It was never created. Rather the path knolles/A 11/liste contains some documents.

This happens because in Cloud Firestore it is possible to create documents under any path and that path can be virtual. In other words, documents can be created under any path regardless of if documents or collections exist in that path.

If you want them to show in your query, you can create documents under the knolles/A 11 path.

But for me personally, when I am in this situation, I usually know the full path to my collections (e.g knolls/A 11/liste) and so I just fetch them directly.

  • Related