customKey not working on read
tzvc opened this issue · 10 comments
- Firebase library (
firebase
,firebase-admin
, etc...) and version: firebase-admin - GeoFirestore version: 4.4.2
Hi there, I'm trying to use a custom key for my geoqueries instead of the default g
but I'm running into some issues.
When I specify a customKey in the GeoFirestore.collection
, then create a query from that and run it, the query is run on g.geohash
instead of the specified customKey location.geohash
.
Upon reading the source code, it appear to me that the customKey is only used when adding new documents.
const geocollection = GeoFirestore.collection('posts', 'location');
const geoQuery = geocollection
.near({
center: new admin.firestore.GeoPoint(query.centerLat, query.centerLng),
radius: query.radius,
})
.where('community', '==', req.params.community)
.limit(10);
const resSnapshot = await geoQuery.get();
Am I missing something here ?
Cheers!
Instead of an await, try doing a traditional promise and apply the catch. I'd love to see what if any error appears.
@MichaelSolati With a traditional then/catch, I dont get any errors, but no results (where they should have been)
const geocollection = GeoFirestore.collection('posts', 'location');
const geoQuery = geocollection
.near({
center: new admin.firestore.GeoPoint(query.centerLat, query.centerLng),
radius: query.radius,
})
.where('community', '==', req.params.community)
.limit(10);
return geoQuery
.get()
.then(v => res.status(200).json(v.docs))
.catch(e => console.error(e));
I believe this issue was documented here too: #199
Also, by looking at the source of geofirestore-core, it doesn't appear to support custom keys as it uses the g
key statically https://github.com/MichaelSolati/geofirestore-core/blob/main/src/api/query-get.ts#L83
What version are you using and can you show me what a document in Firestore looks like?
The custom key shouldn't matter on query as its used to encode into the .g
field.
@MichaelSolati I'm using 4.4.2
and my documents looks like this
{
location: {
geopoint: GeoPoint,
geohash: string
},
// other fields...
}
Ok, so the geopoint that you use in your doc can be any field, but you are right that geofirestore uses the g
property.
Are you manually creating that location
property?
@MichaelSolati The location
property is created in the flutter frontend via https://pub.dev/packages/geoflutterfire, which allows a field name to be specified (which is porb. why I assume this worked the same way)
Got it, unfortunately no, this library doesn't support custom property names for queries, only to encode the document.
It's a good feature for down the road but not something I see myself getting to any time soon.
Fair. If I end up implementing it, I'll make sure to submit a PR ;)
In any case, thank you for your time!