skip to Main Content

I have a Firebase collection named Rooms and sub-collection messages but when I try to retrieve the Rooms collection it only returns the generated document IDs.

I have tried to retrieve it with this code. but it only retrieves the generated document IDs.

final data = await firestore.collection('Rooms').get(); 
for (var doc in data.docs) {
    final event = doc.id;
    print(event);
}

2

Answers


  1. Chosen as BEST ANSWER

    Thanks a lot to those who give me the response to my question. I got the answer from this post.

    The data I added to Firestore is displayed in italic

    The italics style only means that under this document, there are other subcollections present. If you try to query such documents, you won't get a result, since such documents don't exist. So that document is displayed like that for two main reasons. You either deleted the document without deleting all the documents in all of their subcollections, or you didn't create it in the first place.


  2. Try with this:

    final data = await firestore.collection('Rooms').get(); 
    for (var doc in data.docs) {
        final id = doc.id;
        final data = doc.data();
        print(id);     // it return the Document ID
        print(data);   // it return the Document data
    }
    

    I am not sure which ID you want to access by the above code, if you created an id field manually, follow the below instructions.

    final data = doc.data();
    This allows access to the fields created within each document like data['id']

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search