Angular 检索Firestore子集合
我有以下Firestore结构:Angular 检索Firestore子集合,angular,typescript,firebase,google-cloud-firestore,Angular,Typescript,Firebase,Google Cloud Firestore,我有以下Firestore结构: case (col) ----someFirestoreId (doc | Do I need a specific ID?) -------------------name (field) -------------------id (field) -------------------modules (col) --------------------------0 (doc) --------------------------1 (doc) -----
case (col)
----someFirestoreId (doc | Do I need a specific ID?)
-------------------name (field)
-------------------id (field)
-------------------modules (col)
--------------------------0 (doc)
--------------------------1 (doc)
--------------------------2 (doc)
----someFirestoreId (doc | Do I need a specific ID?)
-------------------name (field)
-------------------id (field)
-------------------modules (col)
--------------------------0 (doc)
--------------------------1 (doc)
(0 & 1 each have its own fields)
如何检索此数据
首先,我需要一个数组来保存每个案例及其子集合模块及其文档,但既然我假设这是不可能的,那么有没有特殊的方法来检索此类数据
最后,我需要能够通过迭代模块的文档,从参数路由获取案例id并显示分配的模块0、1、2…
编辑:
这就是我到目前为止得到的:
this.db.collection('test').valueChanges()
.subscribe(val => {
this.casesService.cases = val;
this.casesService.animate = true;
for (let i = 0; i < val.length; i++) {
this.db.collection('test').doc(val[i].name).collection('modules').valueChanges()
.subscribe(value => {
console.log(value);
this.casesService.case = value;
resolve(true);
});
}
});
这就是我需要分配模块的地方0、1、2…
此外,这种方法要求案例集合名称为普通名称,这可能也是一个缺点 你尝试过什么?你在代码中遇到了什么问题?@AJT_82我尝试过,它有点工作,但只是静态的。我需要它是动态的。到目前为止,我所做的只是以静态名称作为路径遍历集合和文档。最后,我得到了一个只用于一个案例及其模块的数组——显然,这对其他案例不起作用,因为它是动态的。这就是我被卡住的地方。你需要向我们展示你的代码并解释你面临的问题:)@AJT_82编辑可能有点混乱,但我已经尽力了。
this.route.paramMap.pipe(
map(paramMap => +paramMap.get('id')),
switchMap((id: number) => this.caseService.getCase(id)),
).subscribe(cases => { this.case = cases;
});