0

Here is my database structure for categories

enter image description here

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

Munish Kapoor
  • 3,141
  • 2
  • 26
  • 41

1 Answers1

4

As per suggested by Frank van Puffelen

I have changed my data structure as following

enter image description here

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

Community
  • 1
  • 1
Munish Kapoor
  • 3,141
  • 2
  • 26
  • 41