[ PLX ]: Complex query in one request

3,207 views
Skip to first unread message

Pavlinux

unread,
Jul 5, 2016, 12:26:52 PM7/5/16
to Firebase Google Group
"Users": { 
      "user1" : {
                "gender" : "M",
                          "geolocation" : {
                                 "latitude" : 11.111,
                                "longitude" : 33.333
                            },
           },
      "user2" : {
                "gender" : "F",
                          "geolocation" : {
                                 "latitude" : 11.111,
                                "longitude" : 33.333
                            },
           },
      "user3" : {
                "gender" : "F",
                          "geolocation" : {
                                 "latitude" : 11.111,
                                "longitude" : 44.444
                            },
           },
}


How to query SQL analog: SELECT * FROM Users WHERE gender='F' AND (latitude >  11 AND latitude < 44) ?

Swift/Obj-C/Android  

Jacob Wenger

unread,
Jul 5, 2016, 12:37:11 PM7/5/16
to fireba...@googlegroups.com
Hey there,

This is not a direct answer to your question, but it looks like you are looking for a geolocation library like GeoFire. In general, since Firebase is a NoSQL datastore, you cannot do complex SQL queries like this. However, libraries like GeoFire can make these kinds of geolocation queries simple, and realtime.

Cheers,
Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/66ba1bd7-5281-4d72-aac0-c4d335f8f185%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pavlinux

unread,
Jul 7, 2016, 11:15:04 AM7/7/16
to Firebase Google Group
OK. How to select from database all Users with gender Male and Age from 25 to 35 and voted for Trump?

вторник, 5 июля 2016 г., 19:37:11 UTC+3 пользователь Jacob Wenger написал:

Jacob Wenger

unread,
Jul 7, 2016, 1:01:58 PM7/7/16
to fireba...@googlegroups.com
You cannot do complex queries like that directly in Firebase. You only can sort / order by a single field at a time. You will have to either combine your indices or do some client-side filter. This has been covered many times previously on this Google Group. Here is a good thread I posted on a year ago which is still the definitive answer.

Cheers,
Jacob

Ryan Mills

unread,
Jul 7, 2016, 5:20:28 PM7/7/16
to Firebase Google Group
Hi Jacob,

Are there any plans to increase query functionality? Querying is severely limited.

Ryan

Jacob Wenger

unread,
Jul 7, 2016, 6:38:27 PM7/7/16
to fireba...@googlegroups.com
Hey Ryan,

We are definitely looking to improve query functionality in the future, but have nothing to announce at present. I'll forward your feedback on to the rest of the team. Many customers export their data into something like BigQuery or Elasticsearch for advanced, non-realtime query functionality. That will have to tide you over until we introduce more advanced query functionality. 

Cheers,
Jacob

Reply all
Reply to author
Forward
0 new messages