Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add an .index in Realtime Database when the folders are not constant?

Whenever I am trying to query some data in order to delete a folder in Realtime Database, I get the following warning:

Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "id" at /comments/evChargers/D6A3D94D-1F2F-467B-A6C5-F6D9BF7D1C02/AKsxbJAifSbsIhFONMSFT6UTarS2 to your security rules for better performance

However, the values D6A3D94D-1F2F-467B-A6C5-F6D9BF7D1C02 and AKsxbJAifSbsIhFONMSFT6UTarS2 are not constant and will change based on some variables in my app. Obviously, the folder names on my Realtime Database have those variables names.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there any way to add dynamic rules in Realtime Database? Thanks in advance!

>Solution :

You can add indexes (and security rules) at a dynamic path by using wildcard capture variable to define it.

So yours could be something like:

{
  "rules": {
    "comments": {
      "evChargers": {
        "$id1": {
          "$id2": {
            ".indexOn": "id"
          }
        }
      }
    }
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading