“不同字段上的范围过滤器"的解决方法局限性? [英] Workaround for "Range filters on different fields" limitation?

查看:15
本文介绍了“不同字段上的范围过滤器"的解决方法局限性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手在这里firestore并努力克服不同领域限制的范围过滤器.

newbie to firestore here and struggling with how to overcome the range filter on different fields limitation.

用例是为日历解决方案存储和检索事件/事件数据.

Use case is storage and retrieval of event/event data for a calendaring solution.

日历视图可以是不同的周、月等,即每个特定视图都有一个定义的开始和结束时间戳.

Calendar views can be different weeks, months etc, i,e each specific view has a defined start and end timestamp.

存储的事件有一个开始时间戳和一个结束时间戳.

Stored events has a start timestamp and an end timestamp.

我需要查询在视图开始和结束时间戳内开始、结束或跨越的所有事件.

I need to query for all events that start, ends within or spans the views start and end timestamp.

用 sql 后端实现它是微不足道的,但是使用 firestore 不同字段的范围过滤器似乎使这变得不可能?任何想法如何解决?或者是否有计划在 Firestore 中支持这种功能?

Implementing this with a sql backend is trivial, but with firestore the range filter on different fields seems to make this impossible? Any ideas how this could be solved? Or if there as plans for supporting this kind of functionality in firestore?

BR斯蒂芬

推荐答案

当我第一次遇到这个问题时,它有助于首先理解为什么存在这个限制.是的,这在 SQL 数据库中可能是微不足道的,但 SQL 数据库不会像 Firestore 那样扩展.Firestore 可能得到 Google Big Table 的支持,由于索引的工作方式,当范围过滤器用于不同的属性时不会缩放.从本质上讲,Firestore 不会让您做一些会在您的应用扩展时困扰您的事情.

When I first encountered this problem it helped to first understand why this limitation exists. Yes, this may be trivial in a SQL database, but a SQL database will not scale like Firestore will. Firestore is likely backed by Google Big Table which, because of the way that indexing works, will not scale when a range filter is used on different properties. Essentially, Firestore isn't going to let you do something that will come to haunt you when your app scales.

我可以为您看到的最佳选择是执行两个查询,然后将结果组合到一个集合中.这是一些 sudo 代码:

Best option that I can see for you would be to do two queries and then combine the results in a set. Here's some sudo code:

let eventsStartingIn2017 = calendar_events.where("start_date", ">=", "1/1/2017").where("start_date", "<=", "31/12/2017")
let eventsEndingIn2017 = calendar_events.where("end_date", ">=", "1/1/2017").where("end_date", "<=", "31/12/2017")

let 2017Events = new Set();
2017Events.add(eventsStartingIn2017);
2017Events.add(eventsEndingIn2017);

这篇关于“不同字段上的范围过滤器"的解决方法局限性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆