I want to upload image information in the database where photoJson
is unique. Before inserting I want to check if it already exists in the database. So I wrote this rule. When in-app I upload info it is duplicating data. I know the question like this already exist but I tested the solution and it's not working.
{
"rules": {
"wallpapers" :{
".read": true,
".write" : true,
"$wallpaper":{
"photoJson": {
//Checking if same wall already exists
".validate": "!root.child('wallpapers').child(newData.val()).exists()",
},
"url": {
".validate": "newData.isString()"
},
"thumbUrl": {
".validate": "newData.isString()"
},
"likes": {
".validate": "newData.isNumber()"
},
"dislikes": {
".validate": "newData.isNumber()"
},
"favorites": {
".validate": "newData.isNumber()"
}
}
}
}
}