【问题标题】:Is it possible to query Field and get main collection field and get sub collection with sub collection documents on cloud firestore?是否可以在云 Firestore 上查询字段并获取主集合字段并使用子集合文档获取子集合?
【发布时间】:2019-12-07 04:42:20
【问题描述】:

我需要查询字段并获取所有子集合和字段。有可能吗?

      Stream<List<ChatFieldModel>> getChatField(String uid) {
        var ref = _db.collection('chats')
             .where('toUserId', isEqualTo: uid);
//Afterthat need to get sub collection with sub collection list of documents and main collection fields value. is it possible?

        return ref.snapshots().map((list) => list.documents
            .map((doc) => ChatFieldModel.fromForestore(doc))
            .toList());
      }

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    Firestore 查询很浅。它们只返回正在查询的集合(或者,如果您使用集合组查询,则返回正在查询的集合)中的文档。

    因此,如果您查询chats,您将只能从该集合中获取文档。要从 messages 子集合加载文档,您需要执行额外的查询/读取操作。

    【讨论】:

      猜你喜欢
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-11
      • 2022-08-20
      • 1970-01-01
      • 2020-05-03
      • 2019-10-06
      相关资源
      最近更新 更多