是否可以在Cloud Firestore上查询Field并获取主集合字段以及具有子集合文档的子集合? [英] Is it possible to query Field and get main collection field and get sub collection with sub collection documents on cloud firestore?
本文介绍了是否可以在Cloud Firestore上查询Field并获取主集合字段以及具有子集合文档的子集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要查询字段并获取所有子集合和字段.有可能吗?
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());
}
推荐答案
Firestore查询很浅.它们仅从正在查询的集合中返回文档(或者,如果使用集合组查询,则返回正在查询的集合).
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.
因此,如果您要查询聊天
,则只会从该集合中获取文档.要从 messages
子集合加载文档,您将需要执行其他查询/读取操作.
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.
这篇关于是否可以在Cloud Firestore上查询Field并获取主集合字段以及具有子集合文档的子集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文