Limitations & Considerations
Compound Queries
Internally GeoFirestore creates multiple geohashes around a requested area. It then makes multiple inequality (<
, <=
, >
, >=
) queries and joins them together into one response. Unfortunately compound queries with inequalities or additional filtering methods such as orderBy
, startAt
and endAt
are impossible with Firestore. To better understand this limitation, see the Firestore docs here.
Data Structure
Documents generated and stored in your Firestore collection by GeoFirestore are typed/structured as:
interface GeoDocumentData {
g: {
geohash: string;
geopoint: GeoPoint;
};
[field: string]: any;
}
g.geohash
is the geohash generated by the library, and is required in order to make the geoqery.
g.geopoint
is the GeoPoint used to generate the g.geohash
field.
Data must be structured this way in order to work, and is why you should use the GeoFirestore library to insert data in order to be able to query it.
Security Rules
Because GeoFirestore adds the g
field and expects a coordinates
field, be sure to update your Firebase Security Rules to reflect the new fields. While not necessary for all applications, the rules below are an example of how you'd check for GeoFirestore specific fields.
match /collection/{key} {
allow write: // Your previous rules here...
&& request.resource.data.g.size() == 2
&& request.resource.data.g.geohash is string
&& request.resource.data.g.geopoint is latlng
&& request.resource.data.coordinates is latlng
}
limit()
The limit
filtering method is exposed through GeoFirestore, however there are some unique considerations when using it. Limits on geoqueries are applied based on the distance from the center. Geoqueries require an aggregation of queries. When performing a geoquery the library applies the limit on the client. This may mean you are loading to the client more documents then you intended. Use with this performance limitation in mind.