[英]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.
我尝试使用firebase管理一个to m结构。 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. 现在我有了
cardList
的ID,我的目标是获取此列表中的所有卡。 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. 为了从
card_list
集合中获取它们,我创建了这个collection('card_list', q => q.where('cardListId', '==', myId)
。之后,我应该以某种方式将值number
与我所使用的card值进行映射需要某种方式。
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 编辑:
card_cardList
是一个集合,它显示卡和cardlist之间的n到m关系
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. 你需要知道,公司的FireStore 没有任何API从多个集合文件在一个单一的步骤。 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. 在您的特定情况下,您应该创建一个以将文件收集到
cards
集合中,然后根据它们之间的关系创建另一个以将文件收集到cards
cardlist
集合中。
For more information, please also take a look at: 有关更多信息,请查看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.