【发布时间】:2019-04-08 20:00:38
【问题描述】:
我们正在构建一个应用,我们需要在其中显示用户发布的附近帖子。仅应在发布后不超过 4 小时的情况下显示帖子。因为 firestore 不提供地理查询,所以我必须进行搜索,返回特定正方形中的所有帖子。这是我当前的查询:
collection("posts")
.where("creation", isGreaterThan: DateTime.now().subtract(Duration(hours: 4)))
.where("location", isLessThan: cornor1OfSquare)
.where("location", isGreaterThan: cornor2OfSquare)
这个查询的问题是,它不允许添加多个where语句过滤不同的字段。
不可能通过一个本地属性和一个服务器端的属性进行过滤,因为我们的应用中有数百万个帖子。
还有其他方法可以做到这一点吗?例如重构服务器上的数据,使这样的查询成为可能?我进行了研究,但只找到了“简单”数据的解决方案。但是我有一个 Timestamp 和一个 GeoPoint 字段,这使得它更加复杂。
我想到的第二种方法是使用云功能,但我不知道该怎么做,也不知道它是否是最好的解决方案。
我正在使用 Dart/Flutter 编程。
【问题讨论】:
-
Logical OR queries. In this case, you should create a separate query for each OR condition and merge the query results in your app. -
应该是and查询。使用 OR 查询,这不是问题。
-
目前无法在 Cloud Firestore 上进行此类查询,因为在 Firestore 的性能保证下无法交付结果。另见stackoverflow.com/q/50658651、stackoverflow.com/q/47581370、stackoverflow.com/q/47288921、stackoverflow.com/q/48027326
标签: firebase dart flutter google-cloud-firestore document-database