Is it possible to query Field and get main collection field and get sub collection with sub collection documents on cloud firestore?

无人久伴 提交于 2021-02-20 03:51:27

问题


I need to query fields and get all sub-collections and fields. Is it possible?

      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());
      }

回答1:


Firestore queries are shallow. They only return documents from the collection that is (or, if you use collection group queries, the collections that are) being queried.

So if you're querying chats, you will only get documents from that collection. To load documents from the messages subcollection you will need to perform an additional query/read operation.



来源:https://stackoverflow.com/questions/59223070/is-it-possible-to-query-field-and-get-main-collection-field-and-get-sub-collecti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!