如何从Firestore中的两个集合中获取数据? [英] How do I get data from two collections in firestore?

查看:47
本文介绍了如何从Firestore中的两个集合中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题.我尝试使用Firebase管理n到m的结构.因此,我做了三个收藏.馆藏| -----卡| ----名称| ----文本| -----卡片清单| ----名称| ----卡数| ----- card_cardList| ---- cardId| ---- cardListId| ----数字

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

现在我有了一个 cardList 的ID,我的目标是获取此列表中的所有卡.为了从 card_list 集合中获取它们,我创建了这个 collection('card_list',q => q.where('cardListId','==',myId).之后,我应该以某种方式将值 number 映射到我需要以某种方式获得的卡值.

Now I have the id of a cardListand 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.

有人建议如何做吗?

card_cardList 是一个集合,显示了卡片与cardlist之间的n到m关系

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

推荐答案

根据评论:

问:那么,您想一次获得此列表中的所有卡吗?

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

A:是的,这就是计划.

A: Yes thats the plan.

您需要知道Firestore 没有没有任何API可以在一个步骤中从多个集合中获取文档.您将必须使用两个(或更多)单独的呼叫.在您的特定情况下,您应该创建一个文件以获取 cards 集合下的文档,并创建另一个文件以根据它们之间的关系获取 cardlist 集合中的文档.

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:

这篇关于如何从Firestore中的两个集合中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆