我的 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/