简体   繁体   English

防止从 Firebase 数据库中删除现有数据

[英]prevent deletion of existing data from firebase database

I want to allow read and write but not delete existing nodes.我想允许读写但不删除现有节点。 these are the rules I have but is still allowing to delete (update)这些是我有但仍然允许删除(更新)的规则

"messages_test": {
    ".read": "true",
    ".write": "true",
    "$message": {
        ".write": "false",
    }
},

火力基地

this is how I´m removing the node (succesffuly, but i should get permission denied instead)这就是我删除节点的方式(成功,但我应该获得权限被拒绝)

    firebase.database().ref('messages_test').child(id).remove()
        .catch(error => console.log(error.message));

thanks for your help感谢您的帮助

I guess I found the way.我想我找到了方法。 restricting the write for existing data限制写入现有数据

"messages_test": {
    ".read": "true",
    "$message": {
      ".write": "!data.exists() && newData.exists()",
    }
},
"messages_test": {
    ".read": "true",
    "$message": {
      ".write": "newData.exists()",
    }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM