1

This is the layout of my firebase database.

MyCollection > MyDocument1 > 1: Data1
                           > 2: Data2
                           > 3: Data3
                           > 4: Data4
                           > 5: Data5
             > MyDocument2
             > MyDocument3

I'm trying to do the multiple fetch but having a difficulty in implementing it. What am I missing?

final FirebaseFirestore db = FirebaseFirestore.instance;
DocumentSnapshot<Map<String, dynamic>> documentSnapshot = await db.collection('MyCollection').where('MyDocument1', 'in',['1','2','3']).get();

enter image description here

Mr. Tacio
  • 442
  • 1
  • 7
  • 18

1 Answers1

1

This is the query you execute:

db.collection('MyCollection').where('MyDocument1', 'in',['1','2','3'])

In here you are looking for a field MyDocument1 in each document in MyCollection and then check whether its value is '1','2' or '3'.

Is that indeed what you want to do? If so, can you show a screenshot from the Firebase console of a document you expect to be returned?


If you just want to read MyDocument1 that'd be:

db.collection('MyCollection').doc('MyDocument1')
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Ohh, then I'm wrong. `MyDocument1` is the document name. The fields of the documents are `'1','2','3'`. Is that possible? – Mr. Tacio Mar 29 '22 at 14:57
  • What do you expect the code to do? If you want to just read that one document, check the update in my answer,. – Frank van Puffelen Mar 29 '22 at 15:00
  • What I wanted to do is fetch let's say 1,2,3. Or maybe 2,3. Or 1,3. But all of those are in the fields. But actually now that you mention, I think my layout is wrong. My fields will have a thousand of fields which I think may exceed the limit per Collection. I think, my fields should be the collection, and fetch multiple collection. – Mr. Tacio Mar 29 '22 at 15:09
  • I found this: https://stackoverflow.com/questions/46721517/google-firestore-how-to-get-several-documents-by-multiple-ids-in-one-round-tri I think this is what I need. Thanks for your help, I noticed now what is my mistake. – Mr. Tacio Mar 29 '22 at 15:11