如何查询文档集合

时间:2021-06-04 14:37:53

标签: firebase google-cloud-firestore angularfire

我是 AngularFire 的新手,我正在尝试使用具有这种结构的 Firestore 数据库:

/departments/<department_document_id>/workers/<worker_document_id>

每个部门文档都有一些字段和一组工人,显然每个工人文档都有自己的字段。

我正在尝试获取特定部门的工作人员列表,因此在我的 DataService 中:

getWorkers(departmentId: string) {
    this.departmentsCollection = this.afs.collection('departments', ref => ref.where('departmentId', '==', departmentId));
    // (?)
}

我假设我应该使用 snapshotChanges()pipe() 来获取 DocumentChangeType 并查询 工人 集合,但我在这一点上被卡住了。我以不同的方式尝试,但没有结果。

有什么帮助/建议吗?

编辑:请注意,departmentId 参数是部门文档的字段,而不是 Firestore 自动生成的 ID。

0 个答案:

没有答案