Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding .indexOn for nested data

Tags:

firebase

I am getting the firebase warning "Using an unspecified index. Consider adding ".indexOn": "E-mail" at /user/544dceb6-98d-4f7e/clients.

The rule I added is:

{
  "rules": {
    "user": {
      "$clients": {
        ".indexOn": ["E-mail"]
      }
    }
  }
}

This is the call I'm making:

firebaseRef.child(authData.uid + "/clients").orderByChild("E-mail").equalTo(this.props.params.clientId).on('value', function(clientSnapshot) { ... }

This is how my data is structured:

database
+ user
  + 544dceb6-98d-4f7e...
      + clients
          + -K96sXIXRUIOK8....
              + E-mail

I suspect the issue has something to do with the two layers of keys but can't find a solution.

Many thanks!

like image 658
kmadill Avatar asked Feb 02 '16 04:02

kmadill


1 Answers

You're missing a level in your rules.json:

{
  "rules": {
    "user": {
      "$userid": {
        "clients": {
          ".indexOn": ["E-mail"]
        }
      }
    }
  }
}

Side note: it is somewhat confusing that you have user (singular) and clients (plural) in the tree. Making them consistent helps in keeping your data structure easier to understand.

like image 195
Frank van Puffelen Avatar answered Oct 04 '22 06:10

Frank van Puffelen