1
 widget.filteredRef= FirebaseFirestore.instance
      .collection('users')
      .doc(widget.uid)
      .collection('incomes')
      .where('date',isGreaterThanOrEqualTo:            startTimeStamp,isLessThanOrEqualTo: endTimeStamp)
      .where('amount',isGreaterThanOrEqualTo: amountFrom,isLessThanOrEqualTo: amountTo)
      .snapshots();

       

Hi, I'm new to flutter. I want to specify a query to retrieve income data from specific range of date and amount of the users as a list from flutter cloud firestore. Example, Date from 01/01/2020 to 01/02/2020 of amount 0 to 1000. But using two where clause or two orderby or one orderby with one where clause is not working. Please tell me the way get as a stream.

Here is my firestore income document link: https://drive.google.com/file/d/1lAbF1t641nBK4hRn5zLT-4eNUQ-FyajW/view?usp=sharing

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vickyees
  • 11
  • 2

1 Answers1

1

You will need to create an Index in the Firebase Console itself. This is because firebase stores basically long arrays of the documents, and does something like this: Query = CorrectIndex[start:end], which it cannot do if the data is not sorted. It makes such indices for every item of the document, but not for any combinations (That would be to expensive for things you probably do not need). So, you need to tell Firebase that it needs to make an correctly sorted index for every combination you want to use, so it can be fast when you start querying. If I am not mistaken, in your error message a link to your firebase console is already given. Click that, and you will be guided through the process.

It is, however, not completely correct. You will need to remake that index to use a "CollectionGroup". Everything else can stay the same. Anyway, some good series about firebase is this: https://www.youtube.com/watch?v=Ofux_4c94FI.

Cgrain
  • 149
  • 6
  • I'm getting the error message, but that does not contain any links as you told. I tried manually adding indexing to Firestore and also via the Firebase CLI, but still, I'm getting the same error. Please guide me on how to do that! Thanks in Advance! – Vickyees Nov 16 '20 at 07:21