MichaelSolati / geofirestore-js

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

geoQuery.query() returns all the documents #46

Closed uslperera closed 6 years ago

uslperera commented 6 years ago

Following code returns all the documents

const db = admin.firestore();
const collectionRef = db.collection('documents');
const geoFirestore = new GeoFirestore(collectionRef);

const geoQuery = geoFirestore.query({
    center: new admin.firestore.GeoPoint(52.1989266, 0.0499472),
    radius: 1,
});
const query = geoQuery.query();
query.get().then((querySnapshot) => {
    querySnapshot.forEach(function (doc) {
        console.log(doc.id, " => ", doc.data());
    });
});

Since the radius has been set to 1 km, it should only return the documents within that range. But this is not working as expected. Can you please let me know if the above code is correct?

MichaelSolati commented 6 years ago

Duplicate of #43 the docs should have been updated to explain this, I'd advise looking at my answer

https://github.com/geofirestore/geofirestore-js/issues/43#issuecomment-428469214

uslperera commented 6 years ago

Thanks mate. Your answer saved my day. It would have been better if docs have clearly stated it.

KSRajkumar45 commented 6 years ago

43 (comment)

Hi MichaelSolati, In react native on listner not working...

MichaelSolati commented 6 years ago

@KSRajkumar45 I'd need to see some code as an example as well as your package.json. hopefully I can help from there

graig12 commented 6 years ago

Hi Micheal,

I have tested this and i am also seeing the same behaviour in which the code is returning all documents, how is i use the following code below i get the correct results.

         const collectionRef = firebase.firestore().collection('Consents').orderBy('g').startAt(2)

         const geoFirestore = new 
        GeoFirestore(collectionRef.where('d.details.ConsentType',"==",consentType))

         const geoQuery = geoFirestore.query({
         center: new firebase.firestore.GeoPoint(lat, long),
         radius: val,
         });

        geoQuery.on("key_entered",function($key, result) {
     console.log(key+result)

        }

      });

On a second note are we able to use firestore pagination as mention in the doc here https://firebase.google.com/docs/firestore/query-data/query-cursors with the library and if so can you point me to any working example ?

graig12 commented 6 years ago

saw the correction uder #43 however i would still like to know if Pagination is possible with the lib

MichaelSolati commented 6 years ago

Pagination is not available. The library effectively does a form of pagination based on the geohash in order to do the query, and since we can not stack startAt (or other similar orderBy modifiers). We also can't do a limit because of how this is an aggregation of queries.

This part of the docs explains in detail why we can't do those two things. However in v3.1.0 you will have limit. I do first need to get through v3.0.0 as it's a massive rewrite, and I'm going through writing tests for it now.

While limit isn't in my current codebase for v3.0.0, you can test it via:

npm install geofirestore/geofirestore-js#v3.0.0

This is very much not guaranteed to be solid, but I do think it works well for what it is, and most kinks have been ironed out.

georgeMorales commented 5 years ago

Paging does not remain possible even if you have a limit?