DarshanGowda0 / GeoFlutterFire

:fire:GeoFlutterFire:fire: is an open-source library that allows you to store and query firestore documents based on their geographic location.
https://youtu.be/MYHVyl-juUk
MIT License
305 stars 261 forks source link

[Feature Request] Update within() to allow for flat data models #30

Closed Carvalho96v2 closed 5 years ago

Carvalho96v2 commented 5 years ago

Currently, within() only takes one possible field as the "position" field, however in my use case I have a flat data model (i.e, geohash and geopoint fields are not in their own collection, but are fields within my main collection).

Thus, my data model looks as follows: User:

As opposed to: User:

Thus, there are 2 separate fields that represent the "position"

I've hacked together my own solution by creating "flat_within" and "_flat_querypoint" methods, which I'll be happy to share and which works for now, but obviously will become an issue as this library grows.

I hope this has been clear :)

DarshanGowda0 commented 5 years ago

Hi @Carvalho96v2, You could make a copy of geopoint in the outer model as an alternative. But, I'm just trying to understand what's the purpose of making it flat, they both are coupled together as a class in the library. Unless there's a specific advantage in making them flat, I don't think it's a necessity for the library!

Carvalho96v2 commented 5 years ago

Hey @DarshanGowda0 , the reason why I'd like a flat model is (correct me if I'm wrong), Firestore does not yet support collection group queries, meaning that I can only query a subcollection if I know which parent collection to query in the first place.

This stackoverflow question explains the use case pretty well.

Do let me know if there is a better workaround that I'm missing :)

Edit: A better representation of my data model using geoflutterfire as is:

User [collection]:

DarshanGowda0 commented 5 years ago

@Carvalho96v2 Yes that's true, but this implementation still doesn't store geopoint/geohash in a subcollection! It's in the same collection stored as a nested object. I think you're confusing nested objects inside firestore documents and subcollections.

Examples of how the document is structured

Screenshot 2019-05-01 at 11 35 46 AM

Another one where you can store the geoflutterpoint inside a nested object

Screenshot 2019-05-01 at 11 36 29 AM

As you can see, the position field in the document is not a subcollection as you think, it's an object in the same document.

Carvalho96v2 commented 5 years ago

@DarshanGowda0 Whoops, my bad. Thanks for clearing that up! I'll close this issue now :)

Its a great library by the way <3

DarshanGowda0 commented 5 years ago

Thanks, @Carvalho96v2 😄