简体   繁体   English

如何从Firestore中的两个集合中获取数据?

[英]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.

相关问题 Firestore join foreach map - 从两个 collections 获取数据 - Firestore join foreach map - get data from two collections 如何从 Firestore 两个 collections 获取数据并将所有数据合并在一起 - how can get data from firestore two collections and merge all data together 如何连接两个 collections 并从 object 数组中获取数据? - How do I connect two collections and get data from an array of object? 如何在本机反应中显示来自两个 Firestore collections 的数据 - How to display data from two Firestore collections in react native 如何从 Firestore 集合中的文档中获取数据? - How do I get the data from a document in a collection in Firestore? 如何在反应中从 firestore 获取特定 id 的数据? - How do I get data on a specific id from firestore in react? 如果我有来自 Cloud Firestore 的其他自定义数据,如何获取用户数据? - How do I get user data if I have other custom data from cloud firestore? 如何从 firebase firestore 异步获取所有父 collections 的所有文档? - How can I get all the documents of a all parent collections asynchronously from firebase firestore? 如何使用 NextJs API、Firebase Firestore、axios 和 TypeScript 从 Firebase 集合中获取数据? - How do I get data from Firebase collection using NextJs API, Firebase Firestore, axios and TypeScript? 如何在MongoDB中联接来自两个集合的数据? - How to join data from two collections in MongoDB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM