【发布时间】:2016-09-08 06:12:36
【问题描述】:
我正在尝试使用 firebase 数据库规则来防止出现负值。
{
"rules": {
"products": {
".read": true,
".write": "auth != null",
".indexOn": ["subgroup", "group", "visibility"],
".validate": "newData.child('quantity').val() >= 0"
}
}
但是,使用模拟器测试规则时,我总是看到 write denied on validate rule:
".validate": "newData.child('quantity').val() >= 0"
我正在使用:
location: /products/-KQ1qLkeI3gefuGSFIL_
和
{
"quantity": 0
}
我正在使用经过身份验证的用户。
知道这里发生了什么吗?
谢谢。
==== 更新:
将规则更改为以下内容并没有帮助:
"products": {
"$product": {
".read": true,
".write": "auth != null",
".validate": "newData.child('quantity').val() >= 0",
".indexOn": ["subgroup", "group", "visibility"]
}
},
另外,数据库设计:
DBRoot
products
-KQ1nPkLeqiTMzEzhrfW
description:"Limited Edition"
quantity: 5
...
【问题讨论】:
-
您可以尝试直接写入产品而不是 /products/-KQ1qLkeI3gefuGSFIL_ 吗?
标签: firebase firebase-realtime-database firebase-security