【发布时间】:2018-06-11 16:45:44
【问题描述】:
我有一个按如下方式组织的 Firebase 数据库。
如您所见,它是一个字典数组(每个字典包含两个条目,'text' 和 'tag')。
它包含以下规则。我想做的是确保 newData 包含一个名为“text”的字符串和一个名为“tag”的字符串。
{
"rules": {
".read": "auth != null",
".write": "!data.exists() || !newData.exists()",
//Can write only Array with text and tag
".validate": "newData.hasChildren(['text', 'tag'])",
"$other": {
".validate": false
},
"text": {
".validate": "newData.isString()"
},
"tag": {
".validate": "newData.isString()"
}
}
}
当我给它以下 JSON 时,它在第 10 行 (".validate": "newData.hasChildren(['text', 'tag'])",) 上显示“模拟写入被拒绝”。
JSON 文件:
{
"3": {
"text": "text message",
"tag": "this is a tag"
}
}
我应该如何编写我的规则? 感谢您的帮助。
【问题讨论】:
标签: json firebase-realtime-database firebase-security