This is first time i am working with Firebase on Android. I am trying to insert unique username in firebase database. That means if the username is already exist then it will not be inserted. My database structure is users->uid->uid:value, username:value .
My database structure is given here -
{ "users" : {
"23fcdc28-3d98-4f9a-804f-63e221d78d67" : {
"uid" : "23fcdc28-3d98-4f9a-804f-63e221d78d67",
"username" : "bbb"
},
"2d72161c-6164-45ea-b1fc-0965b838bf08" : {
"uid" : "2d72161c-6164-45ea-b1fc-0965b838bf08",
"username" : "tazimete"
},
"751d5c88-ce14-4931-9c79-4eae387878bb" : {
"uid" : "751d5c88-ce14-4931-9c79-4eae387878bb",
"username" : "aaa"
} } }
And the rules for the database structure is given here
{
"rules": {
".read": true,
".write": true,
"users": {
"$uid": {
".read": true,
".write": true,
"$username": {
".read": true,
".write": true,
".validate": "root.child('users').child($uid).child($username).val() !== newData.child('username').val()"
}
}
} } }
But its not working. I am trying to solve it by putting rules on admin panel. but if you have any other idea, please share with me with code. Thanks.