I am facing a problem. I want to search a key name (not by value) in firebase database and want to get its 2nd order parent. I have no idea how to do it. If it is not possible, can you suggest any other alternative way (such as restructuring the database in a specific way or anything else) to achieve my goal using firebase? The screenshot of the structure is attached hereby.
Asked
Active
Viewed 675 times
0

Prasenjit Adak
- 23
- 4
-
It would be great if you can share an example of how you are trying to solve the issue. Meantime did you read this documentation https://firebase.google.com/docs/database/web/lists-of-data#sort_data? – juanmhidalgo Apr 14 '18 at 07:28
-
I tried `Query firebaseSearchQuery = mUserDatabase.orderByChild("exp").startAt(searchText).endAt(searchText + "\uf8ff");` but it seems to accept only values, not keys. I read the documentation, but all the orderby queries accept values only. – Prasenjit Adak Apr 14 '18 at 07:38
1 Answers
0
This takes a bit of reframing of the problem. Instead of saying "I want the items with this property", think of it as "I want the items with whatever value for this property".
Query firebaseSearchQuery = mUserDatabase.orderByChild("exp/banana").startAt(" ")
Here the space (" "
) is just the first printable character, so we're matching everything.
While this query will work, it requires that you define an index on exp/banana
for each user. It's very likely that you'll get better results if you create an inverted index in your JSON to allow this specific lookup. For a longer explanation and an example, see my answer here: Firebase query if child of child contains a value

Frank van Puffelen
- 565,676
- 79
- 828
- 807