我正在使用文档数据库(Google Cloud Firestore),并且我正在尝试获取深层嵌套对象集合的所有数据。我还没有办法通过一个简单的调用向Firestore询问所有数据。
我的数据如下所示
Assessment: {
documentid: string
name: string,
email: string,
responses: Response[]
}
Response: {
documentid: string
question: string,
answer: string
}
因此,我试图从评估集中获取所有评估 - 这会带回所有数据,但会回复评估,因此我需要再次调用以获取该数据。
这是我目前正在使用的代码,但它只返回附带答复的1评估,而不是我期待的150。
this.db
.collection("Assessments")
.snapshotChanges()
.pipe(
//append the documentid to each assessment
flatMap(actions => {
return actions.map(a => {
const assessment = a.payload.doc.data() as Assessment;
assessment.documentid = a.payload.doc.id;
return assessment as Assessment;
});
}),
concatMap(assessment => {
return (
this.documentDB
.collection("Assessments")
.doc(assessment.documentid)
.collection("Responses")
.snapshotChanges()
.pipe(
//append the documentid to each response
map(actions => {
return actions.map(a => {
const response = a.payload.doc.data() as WfResponse;
response.documentid = a.payload.doc.id;
return response;
});
}),
//append the responses to the originial assessment object
.map(responses => {
responses.sort(this.sortBySortOrder);
assessment.responses = responses;
return assessment;
})
);
);
})
)
.subscribe(assessments => {
this.queryResult.push(assessments as Assessment);
});
答案 0 :(得分:1)
Google Cloud Firestore似乎不支持此功能。
此问题已在其他地方以其他方式提出,并且他们似乎始终确认Google Cloud Firestore仅支持浅层查询。
请参阅:
https://github.com/GoogleCloudPlatform/google-cloud-php/issues/761
Firestore get all docs and subcollections of root collection