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

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

问题描述

新手将在此处进行存储,并努力解决如何克服不同字段限制下的范围过滤器.

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 支持,其中

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天全站免登陆