【问题标题】:Firestore filtering data flutterFirestore 过滤数据抖动
【发布时间】:2021-09-18 05:02:07
【问题描述】:

像这样从firestore中过滤文档是否会按集合中的文档数或返回的文档数来计算,假设我在集合中有1000个文档并像这样过滤数据以获得20个文档,则被认为是1000个阅读或20个读书?

final ordersRef = firestore.collection("orders");
var query =
    ordersRef.snapshots().map((snapshot) => snapshot.docs.where((doc) {
          DateTime orderDate = DateTime.parse(doc["ordered_at"]);

          return unifyDateFormat(previousDay)
                  .isBefore(unifyDateFormat(orderDate)) &&
              unifyDateFormat(nextDay).isAfter(unifyDateFormat(orderDate));
        }));

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    这只需要 20 次读取。仅对您的查询中匹配和返回的文档数量收费。我看不出您的查询有任何限制。 如果您认为您的查询会匹配很多文档,您应该使用.limit() 来限制应该返回的文档数量。

    FirebaseFirestore.instance
      .collection('users')
      .limit(2) // <--
      .get()
      .then(...);
    

    您可以在documentation 中阅读有关限制的更多信息。文档的Firestore billing 部分也对此进行了说明。

    【讨论】:

      猜你喜欢
      • 2020-07-23
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      • 1970-01-01
      相关资源
      最近更新 更多