本文介绍了消防员|为什么所有必须将过滤器都放在同一字段上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,Firestore不支持在不同字段上使用范围过滤器进行查询,如此处:

Apparently Firestore does not not support queries with range filters on different fields, as described here:

我的问题是,为什么?

例如,我如何按时间和位置查询

HOW can I query by time and location for example:

Firestore.instance.collection('events')
      .where("eventTime", isGreaterThanOrEqualTo: DateTime.now().millisecondsSinceEpoch)
      .where("eventLocation", isGreaterThan: lesserGeopoint)
      .where("eventLocation", isLessThan: greaterGeopoint)
      .where("eventStatus", isEqualTo: "created")
      .orderBy('eventLocation', descending: false)
      .orderBy('eventTime')
      .snapshots(),

(来自用Dart编写的Flutter App的示例)

(Example from Flutter App written in Dart)

我收到以下错误:

我不明白如何不支持这种查询以及如何解决这样的查询?

I don't understand how this is not supported and how to solve queries like this?

感谢您的帮助:-)

谢谢,迈克尔

推荐答案

Cloud Firestore为其允许的任何读取操作提供了强大的性能保证:读取操作所需的时间取决于您正在读取的项目数,而不是取决于集合中的项目数.这是一个非常独特的性能保证,因为这意味着拥有100万用户和拥有10亿用户的查询所花费的时间相同.

Cloud Firestore gives a strong performance guarantee for any read operations it allows: the time a read operation takes depends on the number of items you're reading, not on the number of items in the collection. This is a quite unique performance guarantee, since it means that your queries will take the same amount of time when you have 1 million users as when you have 1 billion users.

Firestore仅提供可以维护此性能保证的查询操作.这是您在Firestore查询API中可能会发现限制的主要原因.

Firestore only offers query operations for which it can maintain this performance guarantee. This is the main reason for the limitations you may find in the Firestore query API.

要解决该限制,通常将对查询中的主字段执行过滤和排序,然后在客户端的辅助字段上进行排序

To work around the limit, you'll typically perform the filtering, and ordering on the primary field in the query, and then sort on the secondary field client-side

如果您想了解有关Firestore的查询功能和限制的更多信息,我强烈建议您观看查询如何在Cloud Firestore中工作?以及其余的了解Cloud Firestore 视频系列.

If you'd like to learn more about Firestore's query capabilities and limitations, I highly recommend watching How do queries work in Cloud Firestore? and the rest of the Get to Know Cloud Firestore video series.

另请参阅:

这篇关于消防员|为什么所有必须将过滤器都放在同一字段上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 15:05