Roger99
Roger99

Reputation: 1002

How to change the name of a Firebase parent node to enable rules with them

I am creating a Firebase database and i want to add rules to my data but i cannot figure out the right way to access my data in the 'rules' section of Firebase. When i set up my default database, the parent nodes defaulted to random letters and numbers like in this data shown below

enter image description here

How can i change the name of these nodes to allow me to access them in the 'rules' section of Firebase or how can I access them with the configuration I have currently?

I have tried to access them like this:enter image description here

and i have also tried nesting another reference inside "rules{}" like "message{}" and "#messageId{}" but none of them have been able to read the data.

Thanks for the help.

Upvotes: 1

Views: 1034

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599776

To a apply rules to every child under a specific node, you use a so-called $ variable.

So in your case:

{
    "rules": {
        "$messageid": {
            ".read": "data.child('timestamp').val() > (now - 300000)",
            ".write": true
        }
    }
}

So the rules under $messageid above apply to every message.

For more information, see the Firebase documentation on using $ variables.

Upvotes: 3

Related Questions