MichaelSolati / geofirestore-js

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

Queries that NOT are geospatial #89

Closed georgeMorales closed 5 years ago

georgeMorales commented 5 years ago

Hi, I have a doubt, if I have a document in firestore introduced with a geofirestore, if I want to make a query that is NOT geospatial, can not I consult with the methods provided by firestore? I already had the application almost built, I was using geofirex but it can be applied limit, I implemented it recently. Now for what I see I have to change all the queries to those documents created with geofirestore although they are not geospatial, because those that are geo if the logical one that has to do them again ... I'm a little lost, please help!

MichaelSolati commented 5 years ago

So I'm not 100% sure if I understand your question, but I believe that you are asking can you use geofirestore to make a non-geoquery to a collection of documents that is either geodocuments or a regular document?

If that is the case you don't need to use the near() method to make a geoquery, you can make standard firestore queries (there are just a few limitations). However this will not play well with regular documents, only documents created by geofirestore.

georgeMorales commented 5 years ago

Hi, @MichaelSolati ... Yes, you understand correctly ... I need to make queries to a document created by geofirestore but non-geoquery and also to the subcollections of that document ... I should also be able to add subcollections to that document created by geofirestore ... In other words, make the same queries or transactions as a regular document but that has been created by geofirestore. Is it possible to consult subcollections, create subcollections, delele and update documents created by geofirestore? You say there may be limitations, what limitations? I have two collections that have documents with a lot of data and subcollections and I have to do all kinds of queries, both geospatial and non-query ... I have already managed to add documents to a collection and consult it ... Thank you very much for your help, I had been stuck in this for a long time and the project was very close, integrating it will cost me a lot, and again thanks for this wonderful library! I will be working hard the weekend.

MichaelSolati commented 5 years ago

The limitations are effectively that you can not use filtering methods such as orderBy, startAt and endAt for queries, however full details of considerations and limitations can be found here.

As far as as sub collections, geofirestore will wrap them as geocollections. If you don't want your subsollection to be geo related but want to be able to get your document via a geoquery you can access the Firestore DocumentReference like so:

const geodocument = geofirestore.collection('some-collection').doc('some-id');
const document = geodocument['_document'];
// To write/use a subcollection without anything geo related
const subcollection = document.collection('subcollection');

Also, about making a non-geoquery to a geocollection, you can just ignore the near method:

const geocollection = geofirestore.collection('some-collection');
geocollection.get().then((geoquerysnapshot) => {
     // Do whatever you want with the results here
});

Finally I'd advise using Stack Overflow for any questions on how to use the library as these aren't specifically errors/issues with the library. Keep in mind most every function/method is well defined on https://geofirestore.com with an explanation of what every class does, what every method does, and what type of object it will return. Virtually every method and class is a 1-2-1 replication of the native classes/methods of the web/admin Firestore libraries.