0

I'm working on a query in Python to get the list of documents (documents of collections) from a Firestore database. I know it's a really simple query, but I can't get the list of documents

cred = credentials.Certificate('keys.json')
firebase_admin.initialize_app(cred)
db = firestore.client()

answer = (db.collection("chat").get())

for i in answer:
  print(f'{i.id} => {i.to_dict()}')

print(len(answer))

I´m able to work this query

answer2 =(db.collection("chat/company/FkLxckrD2TgGGXLghUI8hy1irH93").get())
for i  in answer2:
  print(f'{i.id} => {i.to_dict()}')

The second query gets all the information correctly, but the first one does not work. In the first one I want to get the documents in this example is the one with a blue square

Here is the structure of the Firebase.

Thanks

Structure firebase

Second structure

enter image description here

In the last photo I created a document manually with the same structure as the first one, I´m able to get this one, but not the first.

  • The blue bars are confusing a bit. Note that UIDs are not secret, so can be safely shared. But is the document you're looking to load in the first snippet part of the `chat` collection? Or is it in a subcollection under there? The reason this is important is that data loading is shallow, so loading the documents from `chat` (as you first snippet does) does not load anything from subcollections. – Frank van Puffelen Mar 25 '21 at 03:54
  • Sorry about the bars, that info is a little sensible, It´s just the name of a company, Ex. "Coca-cola", I´m trying to get just the list of those companies (the document in a blue square) to then enter all the companies and access the info inside that company (access de collection of the document). But in summary, first to get the name of all the company documents. chat(collection)->company(document)->conversations(collection)->messages(document). Thanks in advance. – Óscar Contreras Mar 25 '21 at 05:53
  • So you're saying your first snippet does not give you any results, but the second snippet *does*? If so, are there any errors printed? – Frank van Puffelen Mar 25 '21 at 14:32
  • 1
    That´s right, the first one doesn't return anything in the for loop and the len returns 0 (no errrors printed). The second snippet returns the documents with all the information (idTo, message, stats, timestamp, type). – Óscar Contreras Mar 25 '21 at 14:47
  • These are collections and documents created in automatic by an app (flutter), when I add a document of the company (where the first blue square is) and create a similar structure, I´m able to get the information. – Óscar Contreras Mar 25 '21 at 15:06
  • 3
    Does this answer your question? [Why are non auto-generated document Ids are in italics in Firestore console?](https://stackoverflow.com/questions/47731794/why-are-non-auto-generated-document-ids-are-in-italics-in-firestore-console) – Sabito stands with Ukraine Mar 27 '21 at 18:04

0 Answers0