0

I'm trying to load a QuerySnapshot but filter on if a field "f_ID" is within a local List. If it is do not add it.

But with the .where I can not access my local list object. Any way around that?

 List<Map> the_List = new List();
  // map elements format: {'f_ID': xxxx, 'date': xxxx}
  // date is irrelevant to this search
 QuerySnapshot querySnapshot = await Firestore.instance
          .collection('Queue')
          .orderBy('clo_Score')
          .limit(25)
          .where("f_ID" ??????)
          .getDocuments();
Andrew Hsu
  • 61
  • 1
  • 6
  • why cant you access local variables? `int num = 1;Firestore.instance.collection('fields').where('grower', isEqualTo: num) .snapshots().listen( (data) => print('grower ${data.documents[0]['name']}') );` – Peter Haddad Jan 15 '20 at 06:30
  • I'm trying to see if f_ID is within a local list i made, but .where doesn't support that I think? I made an edit in my question to specify that! – Andrew Hsu Jan 15 '20 at 06:35

1 Answers1

0

The .where query for retrieving list of documents is for filtering which documents you can to retrieve.

It allows you to compare the params with equal, more or less conditioning and some other more.

Read more about firestore queries here https://firebase.google.com/docs/firestore/query-data/queries

If you want to check if an id is in your LOCAL list already retrieved, you should use the result of the database query => QuerySnapshot.

querySnapshot.data.documents.where((doc)=> doc['f_ID'] == null)

jamesblasco
  • 1,744
  • 1
  • 9
  • 25
  • Ty for the answer, but I was hoping to put it in the query statement itself to reduce reads/ for better efficiency. Would that be possible? – Andrew Hsu Jan 15 '20 at 07:03
  • .where(!(f_ID_List.contains('f_ID'))) is what I think would work, but not sure if it's allowed within queries – Andrew Hsu Jan 15 '20 at 07:03
  • Check this https://stackoverflow.com/a/52431108/8096916. Firestore can not query docs by undefined fields. – jamesblasco Jan 15 '20 at 11:47
  • If you want to reduce reads you could fill the undefined f_ID params with an empty string and filtering like this .where('f_ID', isEqualTo: '') – jamesblasco Jan 15 '20 at 11:54