Firebase prevent duplicate categories using rule [duplicate]

懵懂的女人 提交于 2020-01-11 07:43:12

问题


Here is my database structure for categories

I want prevent duplicate data using Firebase rules

here is my firebase rule

 {
    "rules": {
    ".read": "auth != null",
    ".write": "auth != null",


    "categories": {
      "$catid": {

       ".validate": "!root.child(newData.child('type').val()).exists()"
      }
    }
} 
}

When I am trying to insert again java it's inserting duplicate of java

how do I prevent to insert duplicate category


回答1:


As per suggested by Frank van Puffelen

I have changed my data structure as following

and also updated Firebase rules as following

{
 "rules": {
   ".read": "auth != null",
   ".write": "auth != null",

 "categories": {
   "$categorie":{
        ".validate": "!data.exists()"
   }
 }
}
}

Now it's not inserting data if data is already there.

Thanks Frank van Puffelen



来源:https://stackoverflow.com/questions/39912201/firebase-prevent-duplicate-categories-using-rule

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