【发布时间】:2019-12-06 00:53:47
【问题描述】:
我从 Firestore 获得了一些数据。有时当我调用获取数据时,该集合尚未创建。 在调用 get 请求之前,如何检查集合是否存在?
Stream<List<ChatModel>> getChat(ChatFieldModel model) {
var ref = _db.collection('chats');
return ref
.document(model.docId)
.collection('messages')
.orderBy('timestamp', descending: true)
.snapshots()
.map((list) =>
list.documents.map((doc)=>ChatModel.fromForestore(doc)).toList());
}
【问题讨论】:
-
您只能通过从集合中读取文档来确定集合是否存在。最便宜的方法是阅读单个文档。您刚刚在这里评论了我对几乎完全相同的问题的回答:stackoverflow.com/questions/54055565/… 这个问题与那个问题有何不同?
标签: firebase flutter dart google-cloud-firestore