仅在 Firestore 中获取具有 child id 的嵌套 collection 数据
get nested collection data with child id only in Firestore
我将 Ionic 4 与 Firestore 结合使用,并使用 AngularFire2
我在 Firestore 数据库中嵌套了 collection
|- service_states # Collection
| collection_id: 12345
| name: Delhi
|- service_cities # Collection
| collection_id: 23456
| name: Delhi
|- service_area # Collection
| collection_id: 3456
| name: Area 1
我还有一个独立的collection
|- profile
| user_id: 8765
| service_area: 3456
如果我有 service_states 和 service_cities 数据喜欢
this.profileCollection = this.aFS.collection('service_states/12345/service_cities/23456/service_ares/3456');
但在这种情况下,我没有 service_area
id 和 service_states
id。
如何仅使用 service_area
id 获取 service_area
的详细信息?
如果您无法构建集合的完整路径(包括任何必要的中间文档 ID),则无法对该集合执行任何操作。您必须能够找到一个集合才能查询它。
如果除了文档中包含的字段的某些值之外,您对文档一无所知,则需要查询顶级集合才能获取它。因此,也许您需要一个新的顶级集合来包含所有服务区域。
我将 Ionic 4 与 Firestore 结合使用,并使用 AngularFire2
我在 Firestore 数据库中嵌套了 collection
|- service_states # Collection
| collection_id: 12345
| name: Delhi
|- service_cities # Collection
| collection_id: 23456
| name: Delhi
|- service_area # Collection
| collection_id: 3456
| name: Area 1
我还有一个独立的collection
|- profile
| user_id: 8765
| service_area: 3456
如果我有 service_states 和 service_cities 数据喜欢
this.profileCollection = this.aFS.collection('service_states/12345/service_cities/23456/service_ares/3456');
但在这种情况下,我没有 service_area
id 和 service_states
id。
如何仅使用 service_area
id 获取 service_area
的详细信息?
如果您无法构建集合的完整路径(包括任何必要的中间文档 ID),则无法对该集合执行任何操作。您必须能够找到一个集合才能查询它。
如果除了文档中包含的字段的某些值之外,您对文档一无所知,则需要查询顶级集合才能获取它。因此,也许您需要一个新的顶级集合来包含所有服务区域。