How can I get data not by ID but by other fields. For example: we have users and we want to get user by email, role, birthday, gender etc.
Asked
Active
Viewed 99 times
0
-
Check the documentation: https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries – Frank van Puffelen Nov 24 '14 at 14:17
-
or https://www.firebase.com/docs/web/api/query/orderbychild.html or https://www.firebase.com/blog/2014-11-04-firebase-realtime-queries.html – Frank van Puffelen Nov 24 '14 at 14:23
-
I have already tried it. When I push the record with setWithPriority() I can set only 1 field and select by this field. But in one case I need to select row by email, in other case - by gender etc – Sergey Nov 24 '14 at 14:44
-
A node has only one priority. But with more recent Firebase versions (what version are you using?), each level in your hierarchy can have multiple indexes. And those are usable with `orderByChild` to accomplish your goal: filtering by email (or any other field). If you tried that already and it's not working for you, you'll need to include a code sample of your try. – Frank van Puffelen Nov 24 '14 at 14:47
-
Finally I have got it ^_^ First of all I set the order and then set condition ref.orderByChild("role").startAt("company").endAt("company").once("value", function(data) { console.log(data.val()); }); Thank you! – Sergey Nov 24 '14 at 15:15
-
Duplicate of http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Nov 24 '14 at 15:56