【发布时间】:2017-07-05 05:54:24
【问题描述】:
设计
- 可以登录应用程序的用户
- 登录用户可以创建客户,这些客户将存储在
node下,其值将是当前登录的用户ID
当前数据库值
{
"customers" : {
"UserId1" : {
"custId1" : {
"customerCode" : "thk",
"customerLimit" : "58866",
"customerName" : "Test New "
},
"custId2" : {
"customerCode" : "thh",
"customerLimit" : "5698",
"customerName" : "Yeth"
}
},
"UserId2" : {
"custId3" : {
"customerCode" : "thh",
"customerLimit" : "5886",
"customerName" : "Test "
},
"custId4" : {
"customerCode" : "tbh",
"customerLimit" : "58669",
"customerName" : "New Test"
}
}
}
}
以下是当前为firebase 中的customers 表定义的规则。
{
"rules": {
"customers":{
".read": "auth != null",
".write": "auth != null",
"$CID":{
"customerName":{
".validate": "newData.isString() && newData.val().length < 100"
},
"customerCode":{
".validate": "newData.isString() && newData.val().length<4 && !newData.exists()"
},
"customerLimit":{}
}
}
}
}
尽管我已经为customerCode 定义了一条规则,即它的值应该小于 4 个字符,但它允许插入 5 个字符。另外,如何添加一个验证来验证每个 customerCode 的唯一性 userId?截至目前,它有!newData.exists(),但它也不起作用。
谁能指导我正确的方向?
【问题讨论】:
标签: android firebase firebase-realtime-database firebase-security