简体   繁体   中英

How do I get data from two collections in firestore?

I have the following problem. I try to manage an to m structure with firebase. Therefore i made three collections. collections |-----cards |----name |----text |-----cardlist |----name |----numberOfCards |-----card_cardList |----cardId |----cardListId |----number

Now I have the id of a cardList and my goal is to get all the cards which are in this list. To get them from the card_list collection i made this collection('card_list', q => q.where('cardListId', '==', myId) . After that i should somehow map the value number with the cards values which I need to get somehow.

Does anyone have a suggestion how to do this?

Edited: card_cardList is the collection which shows the n to m relation between cards and cardlist

According to the comments:

Q: So you want to get all the cards which are in this list in a single go?

A: Yes thats the plan.

You need to know that Firestore does not have any API to get documents from multiple collections in a single step. You will have to use two (or more) separate calls. In your particular case, you should create one to get the documents under cards collection, and another one to get the documents in the cardlist collection based on the relationship between them.

For more information, please also take a look at:

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