0

I'm having trouble setting up a search query within my Firebase database. I put the rules all the way of my search, but I always get the index error.

Below is my structure:

This is my Firebase Rules

My Firebase database structure:

enter image description here

My query:

https://zoome-production-users.firebaseio.com/country.json?orderBy="fullname"&equalTo="Vitor Darela"

Erro:

{ "error": "Index not defined, add \".indexOn\": \"fullname\", for path \"/country\", to the rules" }

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vitor Darela
  • 142
  • 7

1 Answers1

1

In your REST call, you run a query on /country in your database. This query inspects each direct child node of /country to see if it matches your filter. In your JSON data /country/AD does not have a property fullname, so the query will not return anything. Even if you were to add the index that the error message tells you about, it will not return anything.

The query you are trying to do is not possible with your current data structure. You will need to modify your data structure to allow it. It seems that you're trying to to find the countries that have a user with a certain name. To allow that query, add an additional data structure that holds precisely that:

"countries_by_fullname": {
  "Vitor Darela": {
    "AD": true
  }
}

With this additional structure you can find the list of countries by simply reading /countries_by_fullname/Vitor Darela.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807