javascript - Firebase - JS 查询 - 获取一个节点,其中子值具有值为 xxx 的子节点

标签 javascript firebase

我的 firebase 查询遇到了一个小问题。 我想要获取所有我尚未看过的剧集。目前我从 firebase 加载它们并使用 JavaScript 中的过滤功能。但我想尽量减少从 firebase 下载的数据。

所以我只想获取符合此虚拟代码标准的系列:

ref("series").orderByChild("seasons/*/episodes/*/episodeWatched").equalTo(false)

这是我在 firebase 中的结构的一个小输出

series >
    <unique series id>
        seriesName: string
        seasons >
            seasonCount: number
            <season nummer>
                episodes >
                    <episode number>
                        episodeName: string
                        episodeWatched: boolean
                        episodeAirDate: Date

一个更“真实”的例子是:

{ series: 
    [{ 123456: 
        { seriesName: "Mr Robot", 
          seasonCount: 3,
          seasons:
            [{ 0: episodeCount: 10,
                 episodes:
                   [{ 0:
                        { episodeName: "Eps1.0_hellofriend.mov",
                          episodeWatched: true,
                          episodeAirDate: 27-05-2015 }
                    { 1:
                        { episodeName: "Eps1.1_ones-and-zer0es.mpeg",
                          episodeWatched: false,
                          episodeAirDate: 01-07-2015 }
                   ...
                   }]
            ...
            }]
        }                            
   }]
}

我在上面的虚拟代码中遇到了这个“通配符”的问题,我只得到特定节点的值,并且无法连接“orderByChild”函数。

如果我可以连接该函数,我的方法如下:

ref("series").orderByChild("seasons").orderByChild("episodes").orderByChild("episodeWatched").equalTo(false)

目前我尝试了一些带有通配符或类似内容的方法,目前唯一有效的是:

ref("series").orderByChild("seasons/0/episodes/0/episodeWatched").equalTo(false)

但这仅检查:是否检查了第一季的第一集。

有人遇到过这个问题吗?

最佳答案

我认为这是您复制/重组数据库以优化读取的次数之一。

用户/uid/notWatched: { “showId_seasonId_epId”:true }

关于javascript - Firebase - JS 查询 - 获取一个节点,其中子值具有值为 xxx 的子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48308441/

相关文章:

javascript - 使用 Vuex,当项目是对象数组的一部分时,如何从数组中删除它们?

php - Google Firebase 通知无法订阅主题

firebase - 如何将列表作为参数发送到Flutter中的Firebase函数?

java - Android 构建错误 com.google.firebase :firebase-core:16. 0.8

javascript - MeteorJS 身份验证什么时候到位?

javascript - 将鼠标悬停在链接上时如何淡入内容?

javascript - jQuery - 在多个字段上应用多个事件 - 不起作用

javascript - 在第一个音频文件完成后播放第二个音频文件,同时解决移动浏览器上的 play() 限制

javascript - Firebase 排行榜,最佳实现。 SQL 连接和 orderby

javascript - firebase 加载到 DOM 后的事件