Firestore collection documents accessible directly but not with stream()

Question:

I am using simple Firestore database with chats collection inside which each chat document has collection of message documents. If I want to access specific message I can do following request

msg_ref = self.db.collection('chats').document(chat_id).collection('messages').document(msg_id)

I can also access all of the messages for given chat

msgs_ref = db.collection('chats').document(chat_id).collection('messages')
    for doc in msgs_ref.stream():
        print(doc.id)

But I cannot understand why following command returns empty list

chat_ref = db.collection('chats').get()

And as a result this call never enters for loop

chat_ref = db.collection('chats')
for doc in chat_ref.stream():
   print(doc.id)

Looking at example from official documentation

docs = db.collection(u'cities').stream()

for doc in docs:
    print(f'{doc.id} => {doc.to_dict()}')

I completely don’t understand what I might be doing wrong here. Can someone please explain why this is not working

chat_ref = db.collection('chats')
for doc in chat_ref.stream():
   print(doc.id)

And whether I can do anything to fix it?

Asked By: sebap123

||

Answers:

After some more digging on SO I’ve found answer by Doug Stevenson (https://stackoverflow.com/a/72588031/1080517) where he pointed out that if documents are greyed out and in italics those are not actual documents. And I believe this is my case as well.

Answered By: sebap123
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.