简体   繁体   中英

How to JOIN two nodes with AngularFire2 and Firebase?

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.

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);
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM