在下面的代码中,我尝试使用flutter和dart检索firestore中集合中的所有文档。这是最好的方法吗?
Query () async {
QuerySnapshot snapshot = await Firestore.instance.collection("collectionName").getDocuments();
snapshot.documents.forEach((document){
if(document.exists){
print('Documents exist');
}
else {
print('document does not exist');
}
});发布于 2020-07-15 13:00:44
是的,这是从集合中检索文档的方法。此外,默认情况下,firestore会尝试离线缓存数据并从那里加载数据,这有时会阻止它从服务器获取数据,即使服务器具有不同的数据。为了防止这种情况,可以在getDocuments方法中添加源标志,.getDocuments(source: Source.server);如下所示。如果您想以不同的方式构建您的应用程序,那么您可以这样做,但是,您仍然必须调用相同的方法来从firestore检索数据
https://stackoverflow.com/questions/62907651
复制相似问题