I'm trying to create the following structure:
[
{
name: 'tester',
comment: 'first comment',
comments: [
{
name: 'tester2',
comment: 'reply'
}
]
}
]
I have the following security rules set up:
{
"rules": {
".read": true,
"comments": {
"$recording": {
"$comment": {
".write": "!data.exists() && auth != null",
".validate": "auth.name == newData.child('name').val() && newData.hasChildren(['name', 'comment']) && newData.child('comment').isString()",
"comments": {
"$reply": {
".write": "!data.exists() && auth != null",
".validate": "auth.name == newData.child('name').val() && newData.hasChildren(['name', 'comment']) && newData.child('comment').isString()"
}
}
}
}
}
}
}
But when I try to push()
to the comments
attribute of an existing comment, the !data.exists()
in the first .write
fails. Even if it wouldn't, the auth.name == newData.child('name').val()
in the first .validate
would fail.
So my question is: How can I selectively allow a push to an attribute while preventing changes to other attributes? In other words, can I somehow notice if I'm trying to write to /comments/1/2/3 in the .write
or .validate
for /comments/1/2?