使用 where 查询获取 collection 的 subscollection

Get a subscollection of a collection with a where query

如何使用 where 查询获取 collection 的子 collection?这是我到目前为止所做的:

  getTasksByUserId(userId) {
    this.logger.debug(`Getting tasks by user id ${userId}`);
    if (userId) {
      return this.afs.collection('tasks', ref => ref.where('createdBy', '==', userId)).valueChanges();
    }
  }

我的 collection 看起来像这样:

我还想在一个查询中获取 featurestags 的内容。

Firestore 读取操作(包括查询)return 仅来自单个集合的文档。如果您需要 return 来自多个集合的结果,您将至少对每个集合中的文档执行一次读取操作。

考虑一下您是否真的需要将特征和标签放在子集合中,或者它们是否也可以是 top-level tasks 集合中文档中的(嵌套)字段。如果您确实需要它们在子集合中(例如查询它们),请考虑在任务文档和子集合中复制数据。