请考虑以下面向用户的防火墙数据库规则。我想知道是否有办法写一条规则,可以一个一个地删除孩子(朋友),但不是一次全部删除?
在这里,一个简单的删除操作将不能工作,因为朋友要么是空的,要么是有孩子的。然而,它可以被更新为有任何其他的孩子,这意味着所有的孩子可以被一次覆盖。
"user":
{
"$uid":
{
/* user can read all user data */
".read": "$uid == auth.uid",
/* allow to add to friends but not delete */
".write": "$uid == auth.uid && (!data.child('friends').exists() || newData.child('friends').hasChildren())",
/* other user data also needs to be writable */
"name": {},
/* only explicit user data is allowed */
"$other": { ".validate": false },
"friends":
{
"$friend_uid": { ".validate": "root.child('user').child($friend_uid).exists()" },
},
}
}发布于 2016-11-27 09:26:00
根据firebase策略,.write策略是由子策略继承的,因此解决方案是针对每个子策略的.write规则。
"user":
{
"$uid":
{
/* user can read all user data */
".read": "$uid == auth.uid",
/* no writing at this level */
/* ".write": false, */
/* user data is still writable */
"name": { ".write":"$uid == auth.uid" },
/* no longer necessary */
/*"$other": { ".validate": false },*/
"friends":
{
"$friend_uid": { ".write":"$uid == auth.uid" },
},
}
}https://stackoverflow.com/questions/40723172
复制相似问题