MichaelSolati / geofirestore-js

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

Retrieving random document within radius #167

Closed GigaDroid closed 4 years ago

GigaDroid commented 4 years ago

Let's assume there are 300 documents within a given radius. I only want to get a single random document within this radius. Is there an approach to this problem which wouldn't result in around 300 document reads? Applying .limit(1) would only give me the closest document and not a random one (and still result in 300 document reads? Not sure if I understood the implementation correctly).

MichaelSolati commented 4 years ago

I believe I understand the problem but I don't see of a method that doesn't include reading all the documents.

Because the library looks to extend the functionality firestore I'd want the query/logic to be as simple and behave as firestore does.

I don't see how a query like your (just select 1 document randomly that matches a query) would work without the near method, so I do not believe that it can be implemented with the near method.

I'm open to conversation, but I do not think it is possible without reading all docs and does not belong in the scope of the library.