Reputation: 11
I'm trying to query my firestore like,
db.collection("products").where("price",">=","200").orderBy("relevance")
But it's giving an error that, first orderBy must have the field that's been used in range comparison in my case 'price'. As per the official firebase documentation it's given that
If you include a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field.
In my scenario it's important to have this kind of query, is there any way to achieve this?
Upvotes: 0
Views: 326
Reputation: 1405
As you mentioned, the firestore has few restrictions for orderBy()
.
To resolve the issue you are facing, you have to order your result by price
first, then with relevance
.
db.collection("products").where("price",">=","200").orderBy("price").orderBy("relevance")
In above query, the ordering happens first on price
then on relevance
.
A good SO ref - Firestore one range query with order by on different field
Upvotes: 1