0

I am attempting to queuing my Firestone database however whenever I add multiple .where clauses to my query the query fails. Might there an obvious reason for this? I've attached my query below.

Thanks in advance.

Not Working version (show ordered posts for today but the user logged in)

 final Stream<QuerySnapshot> _todayStream = FirebaseFirestore.instance
  .collection("Todo")
  .where('uid', isEqualTo: user_database().getUID())
  .where('date',
      isLessThan: fetchDate().getToday())
  .orderBy("date", descending: false)
  .snapshots();

Working version (show all results for posts made today regardless of user logged in)

 final Stream<QuerySnapshot> _todayStream = FirebaseFirestore.instance
   .collection("Todo")
  .where('date',
      isLessThan: fetchDate().getToday())
  .orderBy("date", descending: false)
  .snapshots();

Working version (only show results posted by user logged in)

 final Stream<QuerySnapshot> _todayStream = FirebaseFirestore.instance
  .collection("Todo")
  .where('uid', isEqualTo: user_database().getUID())
  .snapshots();
mlip
  • 11
  • 1

1 Answers1

0

Queries with multiple conditions need you to define an index yourself, something that isn't needed for queries with only a condition on a single field.

Check the log output of your app, because that contains a message with a direct link to create the necessary index, with all fields pre-populated.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for your reply Frank. Being new to flutter (and coding) I'm unsure how to access the output logs of my program. in particular how to produce a log relevant to the stream referenced above. Might you have any advice on how to do this. Thanks in advance. – mlip May 17 '22 at 00:40
  • Additionally, might there be a solution where I could somehow create multiple queries and join them together. Just for the sake of simplicity. (again new to coding and having a tough time understanding many of the more complicated queries). Thank you in advance – mlip May 17 '22 at 01:17