Reputation: 43
Firebase is awesome for framing data in a single dimension using startAt() and endAt().
However, I have some situations where framing data in multiple dimensions would be very useful. Here are a couple of examples:
Example #1: I want to find all the data within a geo-fence; that is, inside two ranges, one for latitude and one for longitude. lat_min -> lat_max, and lon_min -> lon_max.
Example #2: I have a game set in outer space where I need to know all the events that occurred in a 3-space block during a certain time range. So that becomes a 4-dimensional block: x_min -> x_max, y_min -> y_max, z_min -> z_max, and time_min -> time_max.
Is there any way to do this in Firebase as it stands now? If not, does Firebase have any plans to support event indexing (and framing of queries for those events) in multiple dimensions?
Thanks!
Upvotes: 2
Views: 291
Reputation: 13954
The specific use case you describe, location, is handled by the GeoFire library. Check it out, it will save you a lot of time.
The more general answer involves some trickery to get working in NoSql storage. In general you need to find a way to resolve your data into a hierarchy. GeoFire accomplishes the task by resolving your location data into a geohash. You can learn more about this on Firebase's blog entry about how they built GeoFire.
Upvotes: 3