0

I have a legacy Firebase project i contribute to. In it I have the following rules for the resource songs:

"songs": {
       ".indexOn": ["artist_timestamp"]
 }, 

Which allows me to do things like curl htttp://my-fire-base-ref/songs.json?orderBy="artist_timestamp"

However I can also do orderBy="$priority" which is a property we add to all song objects. This works even though it is not explicitly in the rules json definition. Is this a secretly allowed property??

Thalatta
  • 4,510
  • 10
  • 48
  • 79

2 Answers2

1

According to the documentation for indexing data:

Firebase provides powerful tools for ordering and querying your data. Specifically, Firebase allows you to do ad-hoc queries on a collection of nodes using any common child key. As your app grows, the performance of this query degrades. However, if you tell Firebase about the keys you will be querying, Firebase will index those keys at the servers, improving the performance of your queries.

This means you can order by any key at any time without specifying it as an index, but without a specific index specified for a key, performance may be very bad for large sets of data.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
1

The .priority of each node is implicitly indexed, so you don't need to define an index for it.

Why are you using priorities though? While they still work, using named properties allows you to accomplish the same with more readable code. See What does priority mean in Firebase?

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