Reputation: 147
is this a valid query for Firestore?
return firestore.collection('users')
.where('userInfo.gender', '==', "male")
.where('userInfo.yob','>=',`${data.minYear}`)
.where('userInfo.yob','<=',`${data.maxYear}`)
.orderBy('count','asc')
.limit(5)
.get()
if i want this query to be valid how do i need to structure this? or how do i add the indexes?
Upvotes: 1
Views: 628
Reputation: 17523
It is not. If you're doing a greater-than-or-less-than search on one field, you can't then order your results by another field. You're going to have to do the yob
query first, and then sort the results afterwards.
For more information, you can check out the documentation here, or this helpful video!
Upvotes: 1