简体   繁体   中英

Firestore query by geohash and ordering by date

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM