0

I have my data structure on firebase as in the image. I need ONLY the "Details" of each node in my recycler view. I`m not being able to figure out how the database reference should be in order to get data of details only for each user. Any help will be highly appreciated.

Data structure on firebase

Getting null for details

Getting null for details1

Muzogeek
  • 53
  • 7
  • 1
    In the future, it would be better to paste your code inline, so if the person wants to edit your code, they don't have to rewrite the entire thing. – markbratanov Jan 01 '17 at 19:04
  • However, I would look at your firebase databaseReference: `FirebaseDatabase.getInstace().getReference("Doctors");` I could be wrong but I don't think it's necessary to cite child here. Though your structure is a bit ... well, your going to have to change the code a bit. – markbratanov Jan 01 '17 at 19:05
  • Possible duplicate question: http://stackoverflow.com/questions/28601663/how-to-retrieve-specific-node-from-firebase-database-in-android Check marked answer there. – Sebastiandg7 Jan 01 '17 at 19:06
  • `detailsRef = databaseReference.orderByChild("Details");` – Reaz Murshed Jan 01 '17 at 19:18
  • Please look at the new image I`ve put. I`m getting null for details. – Muzogeek Jan 01 '17 at 19:41

1 Answers1

1

The Firebase Database always returns complete nodes. It cannot return a subset of each node in a query. This is one of the many reasons why the Firebase documentation recommends flattening data.

In your scenario you should split out all the doctor information under separate top-level nodes. E.g.

DoctorsDetails
  Doctor1
    appointTime: 15
  Doctor2
    appointTime: 30
DoctorsLocations
  Doctor1
    location1: ...
  Doctor2
    location2: ...

Now you can bind your recycler view to just the data you need and prevent that your users have to download data that won't be displayed.

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