Distinct query in firebase

3,217 views
Skip to first unread message

Chahit Kumar

unread,
Jul 11, 2016, 9:29:29 PM7/11/16
to Firebase Google Group
I was making engineering subjects database in google firebase table that had following schema and entries :
-Columns:Degree,Strea­m,Semester,Subject (All columns are of string[varchar] datatype while 'semester' column is integer datatype)
-Entries eg:
1)Btech;ECE;1;Engine­ering Mathematics
2)BE;Mechanical;5;Fl­uid mechanics
3)Btech;CSE;3;Web dev
Issue:I am unable to get unique entries in each column by quering it.
Just like in mysql we have : "SELECT DISTINCT Degree from <table name>" would give back :"Btech and BE"
I searched for solutions at google forum and stackoverflow, but it didn't help for getting a DISTINCT alternative in firebase.
Although a work around method would be possible but i was thinking if we had something direct for that for getting faster response/execution of query.

Aurélien C

unread,
Jul 12, 2016, 4:26:22 AM7/12/16
to Firebase Google Group
Hi Chahit

Firebase is more like a NoSQL database than SQL. It's more oriented toward realtime and flexibility, than atomicity and fixed structure.

Maybe you have a look at google cloud datastore if you need SQL-like querying language? https://cloud.google.com/datastore/docs/concepts/overview?hl=fr&_ga=1.226478810.1366252305.1464880814

Otherwise, you can indeed think about workaround such as:
 - query all documents and filter unique field values in your program (if not too many entries)
 - denormalize the data: each time you store a new entry, you would set `/degree/{value}/count` to current value + 1, and decrement on delete. once you've done that, you can just query all `/degree` children with count > 0 which keys would be a distinct list of your main dataset degree values. 

Hope that helps

--
Aurelien
Reply all
Reply to author
Forward
0 new messages