MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
504 stars 58 forks source link

The result is empty Typescript cloud function #71

Closed delphiy closed 5 years ago

delphiy commented 5 years ago

The result is empty Typescript cloud function

MichaelSolati commented 5 years ago

Could you share some code example as well as the output?

delphiy commented 5 years ago

Hi, I know where is the problem but not solution.

The problem that in firestore database , the collection cities(for example) . I saved only position as geopoint because it came from andriod and ios . I do not saved g and l fields.

I only have position which contain geopoint in database so no hash value.

no solution for this

MichaelSolati commented 5 years ago

So documents that can be queried by geofirestore must be added by geofirestore. What you could do is set up a Firestore trigger that will automatically convert your document. (it may look like below)

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { GeoFirestore } from 'geofirestore';

export const geoOnCreate = functions.firestore.document('collection/{key}').onCreate((snapshot) => {
  const geofirestore = new GeoFirestore(admin.firestore());
  const collection = geofirestore.collection('collection');
  const documentReference = collection.doc(snapshot.id);
  const document = snapshot.data();

  // You may need to assign a GeoPoint to the coordinates field of your document
  // or you can tell geofirestore what field to look for the GeoPoint
  document['coordinates'] = new admin.firestore.GeoPoint(0,0);

  return documentReference.set(document, /** You can set the field to use for the coordinates here, if it isn't 'coordinates' */);
});

We don't have an ios/android library yet, but we're looking into android next (and would love someone to step up for ios!) You could also use cloud functions to insert documents with geofirestore (but how you do that is up to you);