1

I am using Angular2 along with Firebase?After searching a lot I got to know that there is no way to do nested query on firebase data,so I need to restructure my database.Could anyone tell me what is the other way to structure my data with some example?

Below is the data structure on firebase

enter image description here

AL.
  • 36,815
  • 10
  • 142
  • 281
  • Yes, you can do nested queries. No, we cannot tell you if there's a better structure since we have no idea what you or your app is trying to do. Help us to help you by providing accurate, complete and brief information. – Jay Mar 02 '17 at 19:14
  • As @Jay said, it is possible to "nest" or "join" Firebase queries. One example of such can be found [here](http://stackoverflow.com/questions/41769360/joining-firebase-queries-in-angularfire2). – J. Adam Connor Mar 03 '17 at 21:28

1 Answers1

0

I had a similar problem with a similar structure.I wanted to match a reference key of one collection to an array of reference keys in another collection. If your need is similar to mine. Here is a solution:

This is what I did :

this.af.database.list('books').subscribe(snapshot=>{
        snapshot.forEach(book=>{
          if(book.authors && book.authors.indexOf(auth.uid)!=-1)
          {
            this.books.push(book);
          }
        })
       
        
      })
Hope it helps. All the best.