简体   繁体   English

这是如何遍历 flutter 中的 Firestore 集合上的文档吗?

[英]Is this how to iterate through documents on a Firestore collection in flutter?

In the code below, I am attempting to retrieve all documents within a collection in firestore using flutter and dart.在下面的代码中,我尝试使用 flutter 和 dart 检索 Firestore 中的集合中的所有文档。 Is this the best way to do it?这是最好的方法吗?

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

Yes, this is the way to retrieve the documents from a collection.是的,这是从集合中检索文档的方法。 Moreover, by default firestore will try to cache data offline and load it from there which sometimes prevents it get the data from server even if the server has a different data.此外,默认情况下,firestore 会尝试离线缓存数据并从那里加载,这有时会阻止它从服务器获取数据,即使服务器有不同的数据。 To prevent that you can add source flag inside getDocuments method, .getDocuments(source: Source.server);为了防止您可以在 getDocuments 方法中添加源标志, .getDocuments(source: Source.server); like this.像这样。 And if you want to architect your application in different ways then you can do it but, you will still have to call this same method to retrieve data from firestore如果您想以不同的方式构建您的应用程序,那么您可以这样做,但是您仍然必须调用相同的方法来从 firestore 检索数据

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何查询集合中的多个文档(Firestore/Flutter) - How to query through multiple documents in a collection (Firestore/Flutter) 如何使用 Flutter 删除 Firestore 中集合中的所有文档 - How to Delete all documents in collection in Firestore with Flutter Firestore/Flutter:遍历文档集合的 ID 和 output 它们作为列表 - Firestore/Flutter: Iterating through the ID of a collection of documents and output them as a list 遍历集合中的所有firestore文档并在flutter中更新它们 - Loop through all firestore documents in a collection AND update them in flutter 循环通过 Flutter 中集合中的 Firestore 文档时的 Null 值 - Null value when looping through Firestore documents in a collection in Flutter 如何遍历 Flutter 中的 Firestore 文档中的字段? - How to iterate through fields in a Firestore Document in Flutter? 遍历 Firestore 集合中的所有文档,并将这些文档添加到 Flutter 中的另一个集合中 - Loop through all documents in a Firestore collection and add those documents to another collection in Flutter 如何通过 flutter 在 Firestore 中搜索收藏? - How to search a collection in firestore through flutter? Flutter 和 Firestore:如何从集合组更新多个特定文档 - Flutter and Firestore: How to update multiple specific documents from collection group Flutter:如何在 Firestore 中获取集合的所有文档名称 - Flutter: How can I get all documents name of a collection in Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM