1

enter image description hereI have search a lot on stackoverflow and read many questions I was having 3 indexOn problem 2 of them are solved and 1 remains I am sorting database and have indexOn on "favorite" and "poet" which runs successfully but I need one more indexOn for numbers inside heart node. query is running successfully but I am getting indexOn warning in android studio

I have tried using variables in place of numbers in database rule but still getting warning

Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding '".indexOn": "heart/+91916*******"' at gazal to your security and Firebase Database rules for better performance

queryFav = FirebaseDatabase.getInstance()
             .getReference(reference).orderByChild(child).equalTo("heart");

above query run successfully but what should be indexOn rule

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Sadique Khan
  • 230
  • 3
  • 9

1 Answers1

2

The message you get means you are running a query that has orderBy("heart/+91916*******") on a node named gazal. To efficiently run that query, you need to have an index on heart/+91916******* to that node in your security rules. But since the +91916******* part of that index probably is dynamic (i.e. you'll have a different value of +91916******* for every user of the app), you'll have to add an index for each user. That is not feasible.

In other words: you current data structure makes it easy to read the users who have hearted a specific poem. It does however not make it easy to determine the poems that a specific user has hearted. To make that equally easy, you'll want to add an additional data structure"

"user_hearts": {
  "+91916*******": {
    "-KjYiXzl1ancR8Pi3MfQ": true
  }
}

With the above structure you can easily read the user_hearts node for the user you're interested in, and then read the poems one by one if needed.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for Frank for such quick response as expected from you. But i have approx 10k+ such nodes so changing structure of database is difficult for me, is it impossible for having indexon on my existing structure? – Sadique Khan Sep 02 '19 at 17:23