【发布时间】:2018-03-30 23:48:36
【问题描述】:
我从 Firebase 收到一个错误:
错误:没有为读取定义索引。 FIREBASE 警告:使用未指定的索引。您的数据将在客户端下载和过滤。考虑将 /checkins 处的 ".indexOn": "read" 添加到您的安全规则中以获得更好的性能。
我的数据结构是:
checkins: {
-KwlbakCMOcjs1UhlqLv: {
read: true,
user: "someuserid"
},
-KwlysmdbSCfTI_Nz0Wo: {
read: false,
user: "someotherid"
}
}
如您所见,checkins 的直接子代是键。根据错误消息,我尝试了多种编写规则的方法,但错误仍然存在:
{
"rules": {
".read": true,
".write": true,
"checkins": {
"$checkinid": {
".indexOn": "read"
}
}
}
}
{
..
"checkins": {
"$checkinid": {
".indexOn": ["read"]
}
}
}
{
..
"checkins": {
".indexOn": "read"
}
}
{
..
"checkins": {
".indexOn": ["read"]
}
}
有趣的是:我试图将它切换到 indexOn 用户,但后来我也得到了一个错误(同样的想法 - 没有定义索引)。 checkins 不是任何事物的孩子,除了您现在看到的用于读/写的规则之外,没有其他规则。
如果有帮助,我的查询是:
db.ref( 'checkins' ).orderByChild('read').equalTo(false).on(...
我尝试使用user 作为索引:
db.ref( 'checkins' ).orderByChild('user').on(...
所以我在这里遗漏了一些关键的东西吗?有任何想法吗?谢谢!
【问题讨论】:
-
最后两个
.indexOn定义应该可以工作,只要你的数据结构确实是/checkins。
标签: javascript firebase firebase-realtime-database