2021年5月2日星期日

Firestore query timestamp and geohash in one query

I'm attempting to query my Firestore database using both a timestamp and a geohash, but the results keep coming back as an empty array. If I only use the geohash or only use the timestamp then I got results, but no results when I use them together. I don't get any errors in the console when running this query either. I'm not sure exactly why this query isn't working, any help would be appreciated. Also of note, I'm using the method suggested within the Firebase docs for handling geohash queries. Here's the code for the query:

    const bounds = geofire.geohashQueryBounds(center, radiusInM);      const promises = [];      for (const b of bounds) {          const q = firebase              .firestore()              .collection('scheduledWorkouts')              .where('date', '>=', start) // start is a Firebase timestamp variable              .where('date', '<=', end) // end is a Firebase timestamp variable              .orderBy('date')              .orderBy('geohash')              .startAt(b[0])              .endAt(b[1]);          promises.push(q.get());      }        Promise.all(promises)          .then((snapshots) => {              const matchingDocs = [];                for (const snap of snapshots) {                  for (const doc of snap.docs) {                      const lat = doc.get('location.lat');                      const lng = doc.get('location.lng');                        // filtering out flase positives                      const distanceInKm = geofire.distanceBetween(                          [lat, lng],                          center                      );                      const distanceInM = distanceInKm * 1000;                      if (distanceInM <= radiusInM) {                          matchingDocs.push(doc.data());                      }                  }              }                return matchingDocs;          })          .then((matchingDocs) => {              console.log(matchingDocs);          })          .catch((error) => {              console.log(error);          });  
https://stackoverflow.com/questions/67362908/firestore-query-timestamp-and-geohash-in-one-query May 03, 2021 at 10:42AM

没有评论:

发表评论