I am trying to make a firestore query to fetch data that is based on geohash and in order of date (shown below).
query = db
.collection('activities')
.where('geohash', '>=', bounds[0][0])
.where('geohash', '<=', bounds[0][1])
.orderBy('geohash')
.orderBy('postedOn', 'desc')
.limit(queryLimit);
However, my query seems to only retrieve based on geohash and not in order of date. I am assuming this may be limitation to firestore. I have thought about combining geohash and date field to be sorted on same field, but that wont work in my case.
Is my query set up wrong? If not, any alternate solution?
CodePudding user response:
Since you first order on geohash
and only then on postedOn
, the results are first sorted on geohash
and only on postedOn
for documents that have the same geohash value (which likely is uncommon). This is the expected result for this type of query.
If you want to show the results in a different order, you'll have to resort the results in your application code.