【问题标题】:Firebase read document count using flutterFirebase 使用颤振读取文档计数
【发布时间】:2021-01-06 21:23:42
【问题描述】:

如果在一个等待下运行一个循环并且我总共有 20 个文档,但我的循环会在检查后过滤掉一些,那么在 firebase 中读取了多少。检查后将需要10个数据。但是为了取用,它需要阅读 20 份文件。那么它会计算多少次阅读?我听说一等一读。但是我的 Firebase 仪表板显示的次数是 5/6 倍。在图片中,我显示了代码。 请告诉我阅读次数是多少?

  Future getUser() async {
    final id = await FirebaseAuth.instance.currentUser();
    userId=id.uid;
    await Firestore.instance.collection('user').getDocuments().then((users) {
      print("loop running");
      for (var user in users.documents) {
        if ((!seenList1.contains(user.documentID)) &&
            (!chosenList1.contains(user.documentID)) &&
            (!showId1.contains(user.documentID)) &&
            (user.documentID != userId) &&
            ("male" == user['gender'])

        ) {


          loc(user['Location'].latitude, user['Location'].longitude).then((result){
            if(result==true){
              setState(() {

                showId1.add(user.documentID)  ;
                showName1.add(user['name']) ;   }

          });

        }
      }
    });
    return ;
  }

【问题讨论】:

  • 如果您想弄清楚代码中发生了多少读取,您应该关闭 Firebase 控制台,因为查看文档需要读取。另见:stackoverflow.com/a/56434555
  • 请分享完整代码。

标签: firebase flutter google-cloud-firestore


【解决方案1】:

getDocuments() 的调用决定了读取的文档数量。所以在你的情况下:

Firestore.instance.collection('user').getDocuments()

这意味着来自user 集合的所有文档都被读取。如果这些文档还没有在设备的本地缓存中,Firestore 将不得不在服务器上读取它们并将它们返回给客户端。

假设您的缓存是空的:这意味着您需要为user 集合中的每个文档以及用于下载这些文档的总带宽付费。

【讨论】:

  • 我知道 getDocuments() 会阅读所有文件,但我的问题是它会收取多少阅读费用。我只是检查这些数据的过滤
  • 您需要为从服务器读取的每个文档付费。您在代码中使用它做什么并不重要:只要检索到文档(在您的代码中,getDocuments()),您就需要为此付费。
猜你喜欢
  • 2019-12-31
  • 1970-01-01
  • 2022-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-07
  • 1970-01-01
  • 2021-12-22
相关资源
最近更新 更多