Avoid create extra childs Firebase

末鹿安然 提交于 2019-12-06 03:54:20

Your validate rule says your post must have atleast those children and not only those children. To ensure no other children can be added you have to add the following to your rules:

{
  "rules": {
    "visitors": {
        ".read": "auth != null",
        ".write": "auth.uid != null",
        "$unique-id": {
            ".read": "auth != null ",
            ".write": "auth != null",
            //This line says the new data must have ATLEAST these children
            ".validate": "newData.hasChildren(['name','mail'])",   
            //You can add individual validation for name and mail here     
            "name": { ".validate": true },
            "mail": { ".validate": true },
            //This rule prevents validation of data with more child than defined in the 2 lines above (or more if you specify more children)
            "$other": { ".validate": false }
        }
    }
  }
}

Take a look here for another example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!