【发布时间】:2017-11-23 23:26:59
【问题描述】:
完成一个项目后,我们意识到我们需要有规则来确保它的安全。所以我们对实时数据库进行了非规范化
"users" :{
".read":"auth != null",
"$companyId":{
"$managedby":{
".indexOn": "mobile"
}
}
},
这就是我们拥有的新 Firebase 规则。现在,即使在移动设备上添加索引后,我也会收到以下警告:
util.js:233 FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "mobile" at /users to your security rules for better performance.
我也在尝试使用以下方法从同一节点获取数据:
return this.afDB.database.ref('users').orderByChild('mobile').equalTo(mobilenum); ( I use Angular)
相同的代码应该可以工作,因为它之前可以工作,现在唯一的问题是我们有两个层次。如果我删除 orderByChild 部分,我会下载所有用户。那么问题出在哪里?
mobilenum 变量数据类型是一个与数据库匹配的字符串。
【问题讨论】:
-
我已经读到应该在索引发生的实际节点之前添加 indexOn。在上面的示例中已经这样做了。
-
我已将整个数据库的读取权限设为 true。我已将值硬编码到 OrderByChild 中,但它不起作用。但是一旦我删除 OrderByChild 它就可以了。 OrderByChild 能走多少层?其次,为什么索引不起作用。?我尝试使用顶部节点中的变量,它会引发错误。
标签: javascript angular firebase firebase-realtime-database