首页 > 解决方案 > Loopback 4 - 从 Firestore 获取子集合

问题描述

Loopback 4 在这里有一个社区维护的 Firestore 连接器:https ://github.com/dyaa/loopback-connector-firestore

如何从以下集合中获取子集合房屋:

{
  village: {
    id: "yaOh(37Na",
    name: "Greenwich",
    houses: {
      house01: {
        address: "1st Street"
      },
      house02: {
        address: "2nd Street"
      }
    }
  }
}

以下代码段仅返回浅层结果:

const village = await this.villageRepository.findOne({where: {id: "yaOh(37Na"}});

console.log(village); // returns {id: "yaOh(37Na", name: "Greenwich"}

标签: typescriptgoogle-cloud-firestoreloopback

解决方案


在从集合中读取的 Firestore 中,仅从该集合中读取数据而不是从其下的集合中读取数据。也没有 API 可以自动从子集合中读取数据。

您必须为要从中获取数据的每个子集合执行单独的读取操作。


推荐阅读