How to JOIN two nodes with AngularFire2 and Firebase?

天涯浪子 提交于 2019-12-08 11:35:02

问题


I have this structure of my Firebase Database

Each library can have several albums. How can I display the albums for each library?

the albumsPerLib: first element is the library key, and underneath each library key, I store the albums keys, that belong to it.

But I'm not used to NoSQL and can't figure how to join the tables to display the albums for each library.


回答1:


so this works:

  getAlbumsThatBelongToLib(libKey:string):Observable<Album[]>{
//get the keys for the lib albums
const albumsPerLib$ = this.db.list(`albumsPerLib/${libKey}`);

//map the returned list of keys
//and get their details from the albums node
return albumsPerLib$
  .map((albumKeys) => albumKeys
      .map( (albumKey) => {
         return this.db.object(`albums/${albumKey.$key}`)
      }))
  .flatMap((res) => {
    return Observable.combineLatest(res);
  });
}


来源:https://stackoverflow.com/questions/40999531/how-to-join-two-nodes-with-angularfire2-and-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!