0

I want to get a list of the documents below in a list in the Cloud Firestore.

enter image description here

I have looked at How to get a list of document IDs in a collection Cloud Firestore? but it does not help me.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
pika3113
  • 45
  • 5

1 Answers1

1

How to get a list of documents in a collection, without taking all the fields in the documents

When you read data from Firestore, you read the entire document, including all fields. There is no way you can only read only some fields. It's the entire document or nothing. Firestore listeners fire on the document level and this mechanism cannot be changed.

If you only need to read the values of two fields, for example, then you should consider storing only those two fields in a separate document. This practice is called denormalization, and it's a quite common practice when it comes to NoSQL databases.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • How do i only add the document field instead of the entire thing into a list? – pika3113 Jul 25 '22 at 09:16
  • Simply by reading only the value of the field inside the document. You can do whatever you want with that field, even add it to a list. – Alex Mamo Jul 25 '22 at 09:31
  • How do I specify to only add specified fields to a list? – pika3113 Jul 25 '22 at 23:40
  • By calling the needed field separately. You might check the [docs](https://firebase.flutter.dev/docs/firestore/usage/#one-time-read). In Flutter it should be `Map data = snapshot.data!.data() as Map;` and to get only the value of a field, use `${data['yourFieldName']}`. – Alex Mamo Jul 26 '22 at 07:08
  • I only know how to get the string of one field value, how do I get the value of the same field in multiple documents, and add each one to a list – pika3113 Jul 26 '22 at 13:36
  • You have to loop through the documents in the collection and get the desired value from each one of them. – Alex Mamo Jul 27 '22 at 07:47
  • So besides that, can I help you with other information? – Alex Mamo Jul 27 '22 at 07:47
  • Can you provide some example code? I'm still not sure sure how to do it – pika3113 Jul 28 '22 at 05:06
  • You should make your own attempt given the information in the answer and ask another question if something else comes up. – Alex Mamo Jul 28 '22 at 09:16
  • So can I help you with other information regarding the initial question? – Alex Mamo Jul 28 '22 at 09:17