gpt4 book ai didi

Firebase 规则 : using parent values to validate?

转载 作者:行者123 更新时间:2023-12-02 15:35:12 25 4
gpt4 key购买 nike

我有这套规则:

{
"rules": {
"facebook_users": {
"$user": {
".read": "$user == auth.id",
".write": "$user == auth.id",
"userData": {
"maxProjects": {
".validate": false
},
"userProjects": {
".validate": ???
}
}
}
}
}
}

如果 userProjects.length > userData.maxProjects,我想让用户不能将子项添加到 userProjects 数组>。由于 ".validate": false 规则,用户已被拒绝写入 maxProjects。如何将 userProjects 的长度与 maxProjects 进行比较?

如果不可能,正确的方法是什么?

最佳答案

您可以使用 root 特殊变量和 child() 来进行比较:

{
"rules": {
"facebook_users": {
"$user": {
".read": "$user == auth.id",
".write": "$user == auth.id",
"userData": {
"maxProjects": {
".validate": false
},
"userProjects": {
".validate": "data.val().length < root.child('facebook_users').child($user).child('userData/maxProjects').val()"
}
}
}
}
}
}

关于Firebase 规则 : using parent values to validate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18875161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com