问题
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