I have endpoints:
/schools/$schoolId/rooms/$roomName/id
/schools/$schoolId/rooms/$roomName/name {must be unique ignoring case}
/schools/$schoolId/rooms/$roomName/{other attributes not relevant i think}
I want no two rooms to have the same name so I'm storing it as the key. I'm converting the names to lowercase before setting the value and so I have these security rules:
{
"rules": {
".read": "auth != null",
".write": "auth != null",
"schools":{
"$schoolId":{
"rooms":{
"$roomName":{
".validate": "$roomName===newData.child('name').val().toLowerCase() && !data.parent().child(newData.child('name').val().toLowerCase()).exists()"
}
}
}
}
}
}
These rules do not allow me to write any new rooms.