Search code examples
firebase-realtime-databasemulti-index

Firebase Database index : information and effects


enter image description here

I m using firebase Database .Planning to have quite a large data collection , I'm trying to use indexes . Making some tests, i don t know if rules i implement are correct let alone improve the queries .Is there a way to have a feedback on those indexations (correct or not, improve or not)

right now i have one class as described in the picture and i have the created the following rule

{
  "rules": {
    ".read": true,
    ".write": true,
      "users": {
       "$user_id": {
         ".indexOn": ["user_id", "username"]
          }
       },
 }

Since i get no feedback from firebase, i don t know if this is correct and improves anything .


Solution

  • Firebase's server-side rules are meaningless without seeing the code that exercises them.

    But at a first glance it seems you're defining your indexes too low in the tree: indexes need to be defined at the location where you run the query. So if you want to run a query on /users, you need to define the indexes on /users:

    {
      "rules": {
        ".read": true,
        ".write": true,
        "users": {
          ".indexOn": ["user_id", "username"]
        }
      }
    }