1
請考慮以下用戶的Firebase數據庫規則。我想知道是否有辦法編寫一個可以一個一個地刪除孩子(朋友)的規則,但不是一次全部刪除?Firebase規則允許兒童逐一刪除
在這裏,一個簡單的刪除操作將不起作用,因爲朋友需要是空的或有孩子。但是,它可以更新爲擁有任何其他孩子,這意味着所有孩子都可以立即被覆蓋。
"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()" },
},
}
}