Reputation: 205
var x = FirebaseFirestore.instance
.collection('Workouts')
.doc(FirebaseAuth.instance.currentUser?.uid)
.collection('allWorkouts')
.orderBy("Date Added", descending: true)
.where("Name", isEqualTo: workout.name)
.limit(limit)
.snapshots();
I have attached the code I am using to query data from my Firestore database. I have a field called 'Date Added' with a space. I have also added the respective index in firebase, with 'Date Added' and 'Name', both being ascending. I get an error below
Is there something I am doing wrong with the query, possibly due to the space in between the 'Date' and 'Added'?
Picture of the DB below where you can see that there are entries.
Upvotes: 0
Views: 418
Reputation: 984
Try moving the Where
clause before the OrderBy
clause, like this:
var x = FirebaseFirestore.instance
.collection('Workouts')
.doc(FirebaseAuth.instance.currentUser?.uid)
.collection('allWorkouts')
.where("Name", isEqualTo: workout.name)
.orderBy("Date Added", descending: true)
.limit(limit)
.snapshots();
Also, you mentioned that you created a composite index
with Date Added
and Name
fields both ascending
, but you are ordering Date Added
as descending
, try fixing that index as attached in image
Upvotes: 2