问题
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