【发布时间】:2021-10-31 22:43:07
【问题描述】:
我们的目标是从 firestore 中检索一个文档,并且对于每个文档,使用来自另一个集合的文档数组来完成它。
Firestore 不支持子集合的“包含”。
在我的例子中,我有一个Test,它有一个完整的“TestResults”数组。测试结果的名称是firebase ID。
到目前为止,我有以下内容:
const result = this.firestore
.doc<Test>(`tests/${testId}`)
.valueChanges({ idField: 'id' })
.pipe(
switchMap((test) =>
this.firestore
.collection<TestResult>(`tests/${test.id}/results`)
.valueChanges({ idField: 'name' })
.pipe
//How to assign my testResults[] to my current test
//And how to return a test?
()
)
);
我想我会写一个tap(results=>test.results =results),但是result 不会是Observable<Test>。
您将如何实现这一目标?将使用相同的逻辑来获取所有测试。
非常感谢您的帮助
【问题讨论】:
-
使用
map而不是tap,让map在改变results后返回test对象
标签: angular rxjs observable rxjs-observables