'Flutter firebase Query

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();


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen