GeoFirestore - Is it possible to combine the methods near() and where() in a GeoQuery?

729 Views Asked by At
 // Queries
 let query = geoCollection
    .where("status", "==", "active")
    .near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: 1000 });

 // Subscribe, add jobs into store and listen for changes
 query.onSnapshot((res) => res.docs && Array.from(res.docs.map((doc) => console.log(doc.data()))));

When I perform the above it doesn't work properly. but if I do this instead it works:

 let query = geoCollection.where("status", "==", "active")

or

let query = geoCollection.near({ center: new firebase.firestore.GeoPoint(latitude, longitude), radius: 1000 });

But not together! Which is what I want.

Here is the link for the Documentation. It's not very detailed, but I tried my best to look into the files and no luck so far. https://firebaseopensource.com/projects/geofirestore/geofirestore-js/

Here is a picture of the structure: enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER

Finally found a solution. It is required that you create an Index in the Cloud Firestore console.

  1. Put your collection name in the first field in my case was "jobs"
  2. Put the "where" property that you are comparing to in the field (Ascending)
  3. Lastly, type g.geohash (Ascending)
  4. Click Save, and wait around 5 and 10 minutes.

enter image description here