javascript - 试图获取父文档的子集合
问题描述
我在 Ionic 3 应用程序中使用 AngularFire2 从 Angular Firestore 数据库中获取数据。在数据库中,我有一个“/Products/”集合,其中的每个文档都有一个“/Versions/”子集合:
在我的应用程序中,我已经获取了产品(转换为 DTO)并想获取它的子版本。我一直在尝试不同的方法,但似乎无法弄清楚如何提及孩子。
这是我使用获取产品的代码:
this.fireStore.collection('/Products/', i => i.orderBy('Title'));
一旦我有了一个Product
对象,我如何获取它的版本?
编辑:有人问我到目前为止有什么代码,但如您所见,我缺少“产品”和相关版本之间的链接:
public getVersionsForProduct(product: Product) : AngularFirestoreCollection<Version>{
var vers = this.fireStore.collection<Version>('/Version/');
return vers;
}
解决方案
没有看到你所有的相关代码很难说,但你可以得到这样的子集合:
public getVersionsForProduct(product: Product) : AngularFirestoreCollection<Version> {
const vers = this.fireStore.collection('Products').doc(product.id).collection<Version>('Versions');
return vers;
}
推荐阅读
- python - 如何拆分列中的多个值并按熊猫中的值分组?
- mysql - 与其他列一起选择 SUM 时不返回行
- python - 为什么 sort() 函数不能应用于列表理解?
- sql - Oracle SQL:从加入日期开始的几周
- python - 列在熊猫交叉表中杂乱无章
- javascript - 承诺和承诺链如何工作?[代码问题]
- javascript - 在 Firefox 中使用 MediaStream API 记录完整的视频屏幕截图,但在 Chrome 中没有
- excel - 将数据验证(下拉)列表添加到一系列单元格?
- python - 如何根据熊猫中的不同条件和列对2个数据框进行分组
- c# - 如何从 foreach 更改为一次显示所有数据?