Rishabh Gupta
Rishabh Gupta

Reputation: 1

Reading data from Firebase database

I want to apply a join operation on 2 nodes in firebase database. How will I do this?

Following is the structure of my database :

I have two nodes : user node and books node I want to traverse books node and For every book I need to find every user's name (available in user node) who like that book . I need to make an array of such names and display it in recycler view. Is there any function which will trigger when all the data will be fetched? Here is my code:

  DatabaseReference bookRef;
bookRef.addOnSingleValueEventListener(new ValueEventListener ){
  @Override
  public void OnDataChanged(DataSnapshot datasnapshot){
    //I will get userReference fromdatasnapshot
    DatabaseReference userReference ;
    userReference.addOnSingleValueEventListener(new ValueEventListener ){
      @Override
      public void OnDataChanged(DataSnapshot datasnapshot){
              //Add Username in arrayList

          } 
      }
  }

}

Upvotes: 0

Views: 52

Answers (1)

Uttam Meerwal
Uttam Meerwal

Reputation: 324

You can add a HashMap<> for storing the likes of user which like the book inside the book node then you will have no need to travrse through the user node you can get the value of like Hashmap and set as recycle view or what you want

Upvotes: 1

Related Questions